Skip to content
instance method

String#eql?

(untyped other) -> bool
eql?(object) → true or false

Returns whether self and object have the same length and content:

Example
s = 'foo'
s.eql?('foo')  # => true
s.eql?('food') # => false
s.eql?('FOO')  # => false

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

Example
s0 = "äöü"                           # => "äöü"
s1 = s0.encode(Encoding::ISO_8859_1) # => "\xE4\xF6\xFC"
s0.encoding                          # => #<Encoding:UTF-8>
s1.encoding                          # => #<Encoding:ISO-8859-1>
s0.eql?(s1)                          # => false

See Encodings.

Related: see Querying.

See also #end_with? #force_encoding #encoding #getbyte also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0