From: Sean T Allen Date: 2007-05-15T01:18:56+09:00 Subject: Re: Ruby Inheritance Question Because you are returning the result of '-'. If you don't specifically have that return an RTDate, it will return the result of Time '-' which is either: time - time => float time - numeric => time yours is the second. As ruby classes are 'open' and you can add methods to them, inheritance might not even be how you want to approach this problem. If RTDate is adding methods and not storing additional instance or class data, you should just be adding yesterday and whatever else as part of the Time class. Mike Hamilton wrote: > I'm very confused at the moment regarding inheritance. I have a class > that inherits from Time as in: > > class RTDate < Time > ...my methods adding to the class > end > > I have the initialize method inherit from the parent class. Here is > where I get confused: > irb(main):001:0> require 'rtdate2.rb' > => true > irb(main):002:0> r = RTDate.new > => Mon May 14 09:12:06 PDT 2007 > irb(main):003:0> r.class > => RTDate > irb(main):004:0> s = r.yesterday > => Sun May 13 09:12:06 PDT 2007 > irb(main):005:0> s.class > => Time > irb(main):006:0> > > Here is what I don't understand - why does s become a Time object > instead of an RTDate object. If I do s = r, then I can get all of my > methods out because s becomes an RTDate object. I'm really confused > because the yesterday method is specific to my RTDate class so how can > the resulting object be a time? > Below is an excerpt from my class thus far: > class RTDate < Time > def yesterday > self - (60*60*24) > end > end > >