Is there an inverse 'member?' method in ruby?
Not in ruby but in ActiveSupport:
characters = ["Konata", "Kagami", "Tsukasa"]
"Konata".in?(characters) # => true
You can easily define it along this line:
class Object
def is_in? set
set.include? self
end
end
and then use as
8.is_in? [0, 9, 15] # false
8.is_in? [0, 8, 15] # true
or define
class Object
def is_in? *set
set.include? self
end
end
and use as
8.is_in?(0, 9, 15) # false
8.is_in?(0, 8, 15) # true