From: Brian Candler Date: 2007-05-20T21:34:58+09:00 Subject: Re: Why was the "Symbol is a String"-idea dropped? On Sun, May 20, 2007 at 10:18:22AM +0900, Rick DeNatale wrote: > On 5/19/07, Brian Candler wrote: > >On Sat, May 19, 2007 at 08:28:24AM +0900, Rick DeNatale wrote: > > >> Ruby symbols are represented by a value computed by shifting the > >> symbols integer representation left 8 bits and setting the low-order > >> byte to 0xFF representation > > > >Perhaps it varies based on the Ruby version you're running; it's not like > >that for me. > > > >irb(main):006:0> :foo.object_id.to_s(16) > >=> "39490e" > >irb(main):007:0> RUBY_VERSION > >=> "1.8.4" > > You can't really see the internal bit representations from ruby, since > they get manipulated before you see them. Much like the class of an > object reported by ruby isn't the same as the object pointed to by its > klass pointer at the C level. > > And even if you could, I was talking about the integer representation > of the symbol, not the object_id. AFAIK, the object_id is the in-memory pointer to the structure of the object (if it's a material object), or is one of the special values: - 0, 2 or 4 for false, true or nil - (n<<1) | 1 for Fixnums None of these is valid as a pointer to a memory location, so they can be recognised immediately as special. So in the above, :foo's object ID looks like a memory pointer to me. It might not be, but then you'd need to guarantee that 39490e could not possibly be a valid memory pointer for some regular object (and also be able to recognise this by inspection, i.e. by looking at the bit pattern) Regards, Brian.