How simplify this part of code:
actor.inspect if actor.is_a? Array or actor.is_a? Hash
I try sth like this, but it dosen't work proper:
actor.inspect if [Array, Hash].each { |c| actor.is_a? c }
How simplify this part of code:
actor.inspect if actor.is_a? Array or actor.is_a? Hash
I try sth like this, but it dosen't work proper:
actor.inspect if [Array, Hash].each { |c| actor.is_a? c }
You're looking for Array#any?
actor.inspect if [Array, Hash].any? { |c| actor.is_a? c }
#each
usually just returns the enumerable. #any?
ors together the result of the blocks.
If you want to match exact classes (and not descendants), you can use:
[Hash, Array].member? a.class
I think you should explain what exactly you need to achieve. Perhaps the only thing you need to check is if your object is an Enumerable
or not, or even if it respond_to?
some particular method.