Or does this method just indicate a unique integer that each object has?
+1
A:
well, it depends on what you mean by "ruby" ;) In jruby it's just a unique integer as far as I can tell.
Also, things like numbers aren't the memory location. I forget all the details and am sure someone will give them to you.
irb(main):020:0> 1.object_id
=> 3
irb(main):021:0> (2-1).object_id
=> 3
jshen
2009-03-19 22:48:20
Fixnum are stored in the object_id bit shifted to the left and with the least significant bit set, see http://stackoverflow.com/questions/2402228/accessing-objects-memory-address-in-ruby/2402440#2402440Your `(2-1)` doesn't make sense, try this instead `(4711>>1).object_id`
Jonas Elfström
2010-03-09 08:47:21
+1
A:
In "normal" ruby (MRI 1.8.x and 1.9.x) it's just a unique value.
This is also the case in IronRuby
Orion Edwards
2009-03-19 22:49:39
+2
A:
It isn't a direct reference to the memory location and the "encoding" is specific to a particular Ruby implementation. If you can read C code, you may find it instructive to look at the rb_obj_id
and id2ref
methods in gc.c
in the Ruby 1.8.6 source. You can also read more about the "encoding" in the "Objects embedded in VALUE" section of the partial translation of the Ruby Hacking Guide chapter 2.
floehopper
2009-03-19 23:12:28