Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

String#===

string === object → true or false

Alias of #==

Returns true if object has the same length and content; as self; false otherwise:

Example
s = 'foo'
s == 'foo' # => true
s == 'food' # => false
s == 'FOO' # => false

Returns false if the two strings’ encodings are not compatible:

Example
"\u{e4 f6 fc}".encode("ISO-8859-1") == ("\u{c4 d6 dc}") # => false

If object is not an instance of String but responds to to_str, then the two strings are compared using object.==.

See also #== #=~ #<=> #[] also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1