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

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -