Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Numeric#eql?

(untyped) -> bool
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.3 · 3.2 · 3.1 · 3.0