Open mauricioszabo opened 5 years ago
Simpler repro uses a = Hamster.from({amount: 0.0}); b = Hamster.from({amount: BigDecimal('0.0')})
.
This is inherited from the idiosyncratic behavior of Hash#eql?
. (That's ::Hash
, not Hamster::Hash
!)
{amount: 0.0}.eql?({amount: BigDecimal('0.0')})
# => false
{amount: BigDecimal('0.0')}.eql?({amount: 0.0})
# => true
Questions:
#eql?
for Ruby's built-in Hash
?Hamster::Hash#==
actually be using #eql?
? It seems that chaining to #==
would be more appropriate.From ri BasicObject#==
:
"Numeric types... perform type conversion across ==, but not across eql?..."
It looks like implementing Hamster::Hash#==
using ::Hash#eql?
is wrong. I'll just look at the git commit history to see if there was a reason why that was done.
Looks like I wrote that code back in 2014! Interesting to see that it has stood up for 5 years, only for a lurking bug to show up now...
I was working on a project, then I've found a case when
a == b
is true butb == a
is false.Minimum code that I could find the error: