Skip to content

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

instance method

Numeric#eql?

eql?(other) → true or false

Returns true if self and other are the same type and have equal values.

Of the Core and Standard Library classes, only Integer, Rational, and Complex use this implementation.

Examples:

Example
1.eql?(1)              # => true
1.eql?(1.0)            # => false
1.eql?(Rational(1, 1)) # => false
1.eql?(Complex(1, 0))  # => false

Method eql? is different from +==+ in that eql? requires matching types, while +==+ does not.

See also #dup #fdiv #divmod #finite? also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0