Hacker News new | past | comments | ask | show | jobs | submit login

> the symbol will resolve to the same object_id every time across systems and processes. If you spin up irb and type :foo.object_id you will see 1092508.

object_id for symbols is not consistent across processes.

   % ruby -e "p :foo.object_id"
   396968
   % ruby -e "p :bar.object_id"
   396968
   % ruby -e ":bar; p :foo.object_id"
   397128
You're getting 1092508 consistently not because it's :foo but because it's the next object_id available for a symbol after all the ones created during IRB startup.



Well dang... that is interesting and not what I expected. So from this I can infer that it also changes if a symbol is garbage collected now. So has the implementation of Object.send changed in Ruby 2.2+ as well? The latest copy of the code I have looked at is 1.9.3.


Yes, symbols that are garbage collected will get new object IDs if they appear again.

https://gist.github.com/mboeh/83338a4e3a6a77689e22




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: