Am Dienstag, 15. Mai 2007, 01:11:51 +0900 schrieb Mike Hamilton:
> 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>
> 
> Below is an excerpt from my class thus far:
> class RTDate < Time
>    def yesterday
>        self - (60*60*24)
>    end
> end

The Operator - return a Time. Cast it to RTDate resp. RTTime.

  class RTTime < Time ; def yesterday ; self - 60*60*24 ; end ; end
  r = RTTime.now

  r.yesterday        # => Sun May 13 19:49:57 +0200 2007
  r.yesterday.class  # => Time

  class RTTime ; def - oth ; RTTime.at super ; end ; end

  r.yesterday        # => Sun May 13 19:49:57 +0200 2007
  r.yesterday.class  # => RTTime

Bertram


-- 
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de