Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Set#===

(untyped other) -> bool
===(p1)

Alias of #include?

Returns whether the given object is an element of self:

Example
set = Set[0, :zero, '0']
set.include?('0')    # => true
set.include?('zero') # => false

Tests equality using hash and eql?.

Aliased as ===, which means that sets may be used in case expressions:

Example
case :apple
when Set[:potato, :carrot]
  'vegetable'
when Set[:apple, :banana]
  'fruit'
else
  'unknown'
end
# => "fruit"

Related: see Methods for Querying.

See also #include? #== #> #<=> also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0