ruby - Overriding == equality operator works only in one direction -
consider next example override == operator return true constantly:
class example def ==(other) return true end end however, works in 1 direction:
exp = example.new puts exp == {} #=> true puts {} == exp #=> false is there way force equality method work in reverse direction?
it's not possible without changing other classes. a == b equals a.==(b). need override == operator second class if want make work.
wiki
Comments
Post a Comment