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
If you want to test if an object is strictly or extends a Hash, use:
value = {}
value.is_a?(Hash) || value.is_a?(Array) #=> true
But to make value of Ruby's duck typing, you could do something like:
value = {}
value.respond_to?(:[]) #=> true
It is useful when you only want to access some value using the value[:key] syntax.
Please note that
Array.new["key"]will raise aTypeError.