Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ruby's object_id method refer to the memory location?

Tags:

ruby

Or does this method just indicate a unique integer that each object has?

like image 622
Ellis Avatar asked Mar 19 '09 22:03

Ellis


2 Answers

It is a combination of many parameters, value, object type, place in memory.
More can be read here

like image 152
Itay Moav -Malimovka Avatar answered Sep 23 '22 16:09

Itay Moav -Malimovka


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.

like image 21
James Mead Avatar answered Sep 21 '22 16:09

James Mead