On Sat, Oct 12, 2002 at 11:44:17PM +0900, Gavin Sinclair wrote:
> > 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, ...

Other objects. A few predefined ones:

irb(main):001:0> false.id
0
irb(main):002:0> true.id
2
irb(main):003:0> nil.id
4

and others dynamically allocated, where the id is (I presume) a pointer to
the data structure. I haven't looked at the source, but I posted a guessed
explanation of why fixnums have odd ids at ruby-talk:53040.

Bignums are normal heap-allocated objects and have normal (even) ids. This
means that the same value can end up being held in two different Bignum
objects:

irb(main):010:0> a=(1_000_000*1_000_000)
1000000000000
irb(main):011:0> b=(1_000_000*1_000_000)
1000000000000
irb(main):012:0> a.id
67798716
irb(main):013:0> b.id
67794296

Brian.