Created
May 18, 2011 09:06
-
-
Save maraigue/978249 to your computer and use it in GitHub Desktop.
Pythonのitem in list(listの中にitemが含まれているかを返す)に近い表記をRubyで出来るように頑張ってみた
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# 「普通にlist.include?(item)使えよ!」って話ではあるのですが | |
# 訳あって書いてみました | |
class Object | |
def in(list) | |
list.include?(self) | |
end | |
end | |
p 1.in([1, 2, 3]) # "true"と表示 | |
p 100.in([1, 2, 3]) # "false"と表示 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment