Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Hash#<
(::hash[untyped, untyped] other_hash) -> bool
self < other → true or false
hash.c
View on GitHub ↗
static VALUE
rb_hash_lt(VALUE hash, VALUE other)
{
other = to_hash(other);
if (RHASH_SIZE(hash) >= RHASH_SIZE(other)) return Qfalse;
return hash_le(hash, other);
}
Returns whether the entries of self are a proper subset of the entries of other:
Example
h = {foo: 0, bar: 1} h < {foo: 0, bar: 1, baz: 2} # => true # Proper subset. h < {baz: 2, bar: 1, foo: 0} # => true # Order may differ. h < h # => false # Not a proper subset. h < {bar: 1, foo: 0} # => false # Not a proper subset. h < {foo: 0, bat: 1, baz: 2} # => false # Different key. h < {foo: 0, bar: 3, baz: 2} # => false # Different value.
See Hash Inclusion.
Raises TypeError if other_hash is not a hash and cannot be converted to a hash.
Related: see Methods for Comparing.