Skip to content

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

instance method

Regexp#===

(untyped other) -> bool
self === other → true or false

Returns whether self finds a match in other:

Example
/^[a-z]*$/ === 'HELLO' # => false
/^[A-Z]*$/ === 'HELLO' # => true

This method is called in case statements:

Example
s = 'HELLO'
case s
when /\A[a-z]*\z/; print "Lower case\n"
when /\A[A-Z]*\z/; print "Upper case\n"
else               print "Mixed case\n"
end # => "Upper case"
See also #== #=~ .union #~ also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0