Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

Hash.try_convert

Hash.try_convert(obj) → obj, new_hash, or nil

If obj is a Hash object, returns obj.

Otherwise if obj responds to :to_hash, calls obj.to_hash and returns the result.

Returns nil if obj does not respond to :to_hash

Raises an exception unless obj.to_hash returns a Hash object.

See also .ruby2_keywords_hash? #< .ruby2_keywords_hash #<= also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1