From: Harrison Reiser Date: 2007-04-14T08:27:37+09:00 Subject: Re: Question about Fixnum Hah! Much makes sense now. I was often curious as to why Fixnums' object IDs are always equal to 2*n+1; the ID is also the storage mechanism. Thanks for this. Harrison Reiser On 4/13/07, Gary Wright wrote: > > On Apr 13, 2007, at 1:36 PM, Tim Pease wrote: > > Fixnum objects are immediate objects in the Ruy source code (other > > immediate objects are nil, true, false, and symbols). These immediate > > objects occupy 4 bytes of storage (unsigned long) on most machines. > > They are accessed by casting and bit shifting in the Ruby source code. > > As long as you think of this description ('immediate objects') as > entirely an implementation issue, I think it is useful. When you > switch to talking about Ruby language semantics, I think it is > better to simply think of Fixnum objects and references as the same > as all other Ruby objects and references. Same for NilClass, > FalseClass, and TrueClass. The differences are that the language > provides literal representations of these references > (-1,0,1,nil,false,true) and also ensures that object identity and > object equivalence are the same for their respective classes (for > example, #dup has no meaning for these objects and you can't create > new instances of NilClass, FalseClass, and TrueClass). > > Gary Wright > > > > >