Python has really elegant syntax for checking a value against several patterns.
2 in [1,2,4] #=> True
6 in [1,2,4] #=> False
Order in Ruby version just feels wrong:
[1,2,4].include?(2)
I understand that include? makes a lot more OO sense than 2.included_in?([1,2,4]), I still don’t like it. Ruby even has in keyword but it seems to only be used in construct for i in [1,2,4], not for membership tests.
Another way is this:
(case 2 when 1,2,4 then true end)
Quite verbose, but allows patterns test:
(case file_name when "README", /\.txt\z/ then true end)
Still not very readable.
Am I missing some really nifty way by chance?
$ gem install sane
$ irb