Skip to content

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

instance method

Range#eql?

eql?(other) → true or false

Returns true if and only if:

  • other is a range.

  • other.begin eql? self.begin.

  • other.end eql? self.end.

  • other.exclude_end? == self.exclude_end?.

Otherwise returns false.

Example
r = (1..5)
r.eql?(1..5)                  # => true
r = Range.new(1, 5)
r.eql?('foo')                 # => false
r.eql?(2..5)                  # => false
r.eql?(1..4)                  # => false
r.eql?(1...5)                 # => false
r.eql?(Range.new(1, 5, true)) # => false

Note that even with the same argument, the return values of == and eql? can differ:

Example
(1..2) == (1..2.0)   # => true
(1..2).eql? (1..2.0) # => false

Related: Range#==.

See also #entries #exclude_end? #end #first also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0