From: Joel VanderWerf Date: 2003-10-02T05:12:53+09:00 Subject: Re: Making == symmetric? Zach Dennis wrote: > But on the Polar Points and the Cartesian Points, wouldn't > you want them to inherit from the Point class and allow the > Point class to handle conversions, translations of it's > instantiated objects? Why would you want == to handle the > translation/conversion from Polar to Cartesian. Shouldn't the > class Point handle that itself outside of equality comparion. > > Why have 2 Point classes? Why not just have 1 that has 2 methods: > > convertToCartesian > convertToPolar > > and then check for equality. You're probably right. One class with implementation hidden from the user is better. Even if you want to specify to #initialize that, internally, a certain coordinate system would be optimal for the kinds of operations you are about to do with this point yadda yadda, that doesn't really justify having two classes. I was trying to come up with an analogue of 1 == 1.0 for some other kinds of entities besides numbers. Maybe if you subclass String in a semantically uninteresting way: class MyString < String def <<(s) raise if s == "bad data" super end end my_string = MyString.new my_string << "x" << "y" if my_string == "xy" puts "found xy" end In this case, == already does the right thing, though.