Is there an elegant way to write
if o.class == ClassA or o.class == ClassB or o.class == ClassC
I’m not specifically looking to compare classes, it was just an example where I wasn’t doing things with booleans so I can’t do something like
if o.class == (ClassA or ClassB or ClassC)
Other examples are
if string == "asdf" or string == "1337"
The only thing that I’ve found seems to be
if [ClassA, ClassB, ClassC].include? o.class
or
if ["asdf", "1337"].include? string
I think the most elegant solution is the one you already provided, which is using ‘include?’.
Just for the sake of variety, you also have the option of using a case when:
Another alternative, which I believe is just a tad more readable than ‘include?’ is to create your own ‘in?’, for example:
and then you can use