How do I create a method like:
def process_by_type *things
things.each {|thing|
case thing.type
when String
when Array
when Hash
end
end
}
end
I know I can use kind_of?(Array), etc. But I think this would be cleaner, and I cant’ find a method for it on the Class:Object documentation page.
Using the form of case statement like what you’re doing:
is equivalent to performing a bunch of if expr === obj (triple-equals comparison). When expr is a class type, then the === comparison returns true if obj is a type of expr or a subclasses of expr.
So, the following should do what you expect: