These two operator in Ruby look similar but can have different results when comparing Numeric operators.

1.0 == 1 #=> true
1.eql? 1 #=> false

As stated in the docs only override the ‘==’ if needed.



    • Fred February 28, 2014
    • Reply

    I think you meant to write either

    1.eql? 1.0 #=> false
    1.0.eql? 1 #=> false


    1.eql? 1 #=> true

    The reason is that numeric types perform type conversion across == but not eql?

Leave a Reply

Screen Shot 2013-12-08 at 9.49.35 PM

I have helped a dozen companies build and optimize their engineering teams to deliver great products.

Let’s work together and I can align your business needs with your technology initiatives.