Your first method is idiomatic Ruby. Unfortunately, Ruby does not have the Python a in [1,2] equivalent, which I think would be nicer. Your [1,2].include? a [1,2].include? a is the closest alternative, and I think it is a little back from the most natural way.
Of course, if you use this a lot, you can do this:
class Object def member_of? container container.include? self end end
and then can you do a.member_of? [1, 2] a.member_of? [1, 2] .
Peter 03 Feb 2018-10-03T00 : 00Z
source share