From: Mark Hahn Date: 2001-12-29T07:59:42+09:00 Subject: [ruby-talk:29597] RE: extending method of class A to support arguments of class B by promoting `self' to class B > it should be promoted to Complex Is this possible? I've wanted to change an object's type before inside a method of that object, but I didn't think it was possible. Or did you mean "return" a Complex object. That is all you really need to do in the case you describe. -----Original Message----- From: Debian User [mailto:taw@pa76.chojnow.sdi.tpnet.pl]On Behalf Of Tomasz Wegrzanowski Sent: Friday, December 28, 2001 2:54 PM To: ruby-talk ML Subject: [ruby-talk:29596] extending method of class A to support arguments of class B by promoting `self' to class B (Names of classes chosen arbitrarily, just to show issue) Class Real has method `*' that can use argument Real. I make class Complex. Class Complex also has function `*' which can take either Real or Complex argument. Object Complex can be created from Real by Complex.new(real_object). I want to tell Ruby, that when Real object is called with Complex argument it should be promoted to Complex and then appropriate Complex method be called. The only method I found is renaming all such methods to something like `old_multiply', and redefining Real `*'. Is there any better way ?