D
David Dyer-Bennet
I had a class that included Comparable and defined <=>, I think
correctly, where a check for != between objects was returning false
when it should have returned true. Reading carefully, Comparable says
it defines a bunch of comparison operators, but *not* !=. Ruby
documentation says that != comes automatically from ==, though.
Anyway, I changed the class to get rid of comparable and define ==
(I'm at the playing level, but in fact inequality comparisons aren't
important for this class anyway), and things started working as I
expected.
Are there weirdnesses to how these things work that I'm missing? Or
is it most likely that I just had something simple wrong and didn't
realize it, and managed to accidentally fix it while thrashing around
(these things happen!)? Should my <=> + Comparable implementation have
provided a !=?
(I'm coming to Ruby from almost 4 decades of programming experience,
and considerable C++ and object-oriented perl and PHP work, which no
doubt biases the particular kinds of newbie mistakes I will commit.)
correctly, where a check for != between objects was returning false
when it should have returned true. Reading carefully, Comparable says
it defines a bunch of comparison operators, but *not* !=. Ruby
documentation says that != comes automatically from ==, though.
Anyway, I changed the class to get rid of comparable and define ==
(I'm at the playing level, but in fact inequality comparisons aren't
important for this class anyway), and things started working as I
expected.
Are there weirdnesses to how these things work that I'm missing? Or
is it most likely that I just had something simple wrong and didn't
realize it, and managed to accidentally fix it while thrashing around
(these things happen!)? Should my <=> + Comparable implementation have
provided a !=?
(I'm coming to Ruby from almost 4 decades of programming experience,
and considerable C++ and object-oriented perl and PHP work, which no
doubt biases the particular kinds of newbie mistakes I will commit.)