From: Rick DeNatale Date: 2008-02-13T06:27:04+09:00 Subject: Re: Subclassing Integer; solved! On 2/12/08, Clifford Heath wrote: > Rick DeNatale wrote: > > I don't think this does what you think: > ... > > class Year < Integer > > end > > > > Year.new(2008).class # => Fixnum > > Year.new(2008) == 2008 # => true > > That's exactly what I want. I also want to be able to do > Year.include module, and Year.new.extend module, adding > instance variables and methods to both the Year class and > year instances, and I can't see any other way to do that, > while maintaining the *appearance* of an integer subclass. > Can you? Well this doesn't do it. Using the above code but adding a method to Year. class Year < Integer def foo end end Year.new(2008).class # => Fixnum Year.new(2008).foo # => # ~> -:18:in `send': undefined method `foo' for 2008:Fixnum (NoMethodError) # ~> from -:18:in `method_missing' # ~> from -:35 The point is that Year.new isn't returning a Year which looks like a Fixnum, it IS returning a Fixnum. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/