To check what @some_var
is, I am doing a
if @some_var.class.to_s == \'Hash\'
I am sure there is a more elegant way to check if
In practice, you will often want to act differently depending on whether a variable is an Array or a Hash, not just mere tell. In this situation, an elegant idiom is the following:
case item
when Array
#do something
when Hash
#do something else
end
Note that you don't call the .class
method on item
.