From: Ned Konz Date: 2001-09-27T14:55:20+09:00 Subject: [ruby-talk:21762] Re: inheritance Surprise! On Wednesday 26 September 2001 10:05 pm, ts wrote: > >>>>> "F" == Florian G Pflug writes: > > F> Maybe the standard library should (in the long term) be converted to > avoid F> such problems by either using self.class.new in such cases. > > If you do this you enter a new rule. This new rule will conflict with an > existent rule. Not in this case; we are adding a Number to a Time (or a class derived from Time) and should be returning the same class as self (that is, Time+number => Time, MyTime+number => MyTime). There's really no excuse here not to use self.class.new . The discussion that you referred to was what to return with two Array classes added together; that's not at all the same thing. Smalltalk handles some of these problems by using "species" in some (but not all) cases (which defaults to "self class"); however, with Ruby's mixins I don't think this is necessary (the major use of species is in Collection subclasses; Ruby mixes in Enumerable instead). -- Ned Konz currently: Stanwood, WA email: ned@bike-nomad.com homepage: http://bike-nomad.com