From: Gavin Sinclair Date: 2002-10-12T23:44:17+09:00 Subject: Re: Things That Newcomers to Ruby Should Know From: "Brian Candler" [snipped] > > However in practise this is efficient, since there appears to be a very > compact internal representation of references to Fixnums: > > irb(main):001:0> 0.id > 1 > irb(main):002:0> 1.id > 3 > irb(main):003:0> 2.id > 5 When I discovered this some time ago, I wondered deeply what might be occupying id #s 2, 4, 6, ... Interesting that "id" is documented in 'ri' to return a Fixnum, but: 1000000001.id => 2000000003 1000000001.id.class => Bignum I'm surprised that numbers that high have a predictable ID, as if they're predefined. But then maybe the numbers are brought into being only as needed (except for the first 100, like Python), with a special case formulaic approach to assigning them an ID, and then all non-Integers are given an even ID so they don't clash. When I ran a = [] ObjectSpace.each_object { |obj| a << obj } a.find { |obj| obj.id % 2 == 1 } it returned nil, so that must be the case. What I also found interesting was that successive runs of this testlet seemed to produce many more objects. Any comments? Gavin