Skip to content

Instantly share code, notes, and snippets.

@maraigue
Created May 18, 2011 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maraigue/978249 to your computer and use it in GitHub Desktop.
Save maraigue/978249 to your computer and use it in GitHub Desktop.
Pythonのitem in list(listの中にitemが含まれているかを返す)に近い表記をRubyで出来るように頑張ってみた
#!/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