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
numeric.c
View on GitHub ↗
static VALUE
num_eql(VALUE x, VALUE y)
{
if (TYPE(x) != TYPE(y)) return Qfalse;
if (RB_BIGNUM_TYPE_P(x)) {
return rb_big_eql(x, y);
}
return rb_equal(x, y);
}
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.