Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
class method
Hash.try_convert
[U, V] (::_ToHash[U, V]) -> ::Hash[U, V]
(untyped) -> (::Hash[untyped, untyped] | nil)
Hash.try_convert(obj) → obj, new_hash, or nil
hash.c
View on GitHub ↗
static VALUE
rb_hash_s_try_convert(VALUE dummy, VALUE hash)
{
return rb_check_hash_type(hash);
}
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.3 · 3.2 · 3.1 · 3.0