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?

> There's a lot of good advice in the referenced thread from experienced
> Rubyists about why this is not such a good idea in general.

Heh... seven years and counting myself. It's not a good
idea in general. But this is not in general, it's in the
specific case of a data modeling API, where it is a good
idea to makes things *appear* consistent. It means that
my meta-programming doesn't have to include Integer as a
special case in hundreds of locations.

> Ruby doesn't require forcing classes to inherit in order to conform to
> a type system. Going through hoops to do so is a symptom of thinking
> in Java or C++ rather than in Ruby.

All true. I don't really care about the type system, I
care about the POLS which Ruby so freely violates with
Integers. All for good reasons of course, but my hack
doesn't reduce performance of normal integers, it just
makes Ruby work consistently.

Clifford Heath.