From: Hugh Sasse Staff Elec Eng Date: 2002-09-20T01:49:52+09:00 Subject: Re: subclassing Integer On Fri, 20 Sep 2002, John Tromp wrote: > I'm writing a state space search program where each state can be consisely > described by an Integer. I need these states to have several new methods. > > I can either [...] > class State < Integer > def initialize(n) > super(n) > end > end > > a=State.new(5) # -> undefined method `new' for State:Class (NameError) Do you need to know the number when you create it? I'm wondering how far Object#id gets you -- i.e. that each object already "knows" its own number. I can't remember/find how to get back from the number to the object though. > > The only reason I would try option 2) is that > I expect to have 100s of millions of these States around, > and like 3) it might save memory. Using the ids should help here I think because they exist anyway. Hugh