From: Tomasz Wegrzanowski Date: 2001-12-29T09:16:49+09:00 Subject: [ruby-talk:29604] Re: promoting self to subclass (was extending method of class A ...) On Sat, Dec 29, 2001 at 01:01:35AM +0100, Mark Hahn wrote: > Why not allow a method to "promote" it's object to a subclass of the object? > I've wanted to do this before in ruby and Java. It should be somewhat easy > in ruby and nearly impossible in a static language. > > How about making it: self.promote(Klass) or maybe Kernel::promote(Klass) ? > The same code that does the promotion could set the extra instance > variables. Or, even better, the initializer of the subclass could be called > with params from the promote call: self = Klass.new(*params). In general > this could be considered "assignment to self". > > Where I've run into this need is when an initializer realizes that, based on > input params, there is a more specific class for this data. Another case is > when an object is created and the "type" gets refined later. If you want a > specific example of this being used, let me know. How can it be used in presented Real/Complex case ?