Skip to content

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

Returns whether the entries of self are a subset of the entries of other:

Example
h0 = {foo: 0, bar: 1}
h1 = {foo: 0, bar: 1, baz: 2}
h0 <= h0 # => true
h0 <= h1 # => true
h1 <= h0 # => false

See Hash Inclusion.

Raises TypeError if other_hash is not a hash and cannot be converted to a hash.

Related: see Methods for Comparing.

See also #< #== .try_convert #> also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0