Issue #5805 has been updated by Thomas Sawyer.


Thank you for 1.9.3+ definition, I will add that. Do you happen to know definition for 1.8.7? I am not worried about anything older than that.

> Even if the method were added, it would never affect 1.9 or earlier, so it changes nothing for 1.8.7. Is the target of your library only 2.0 or later?

That's true. But if the definition should ever change again, this issue will come up again. So I think still better that Ruby make it's definition accessible.

----------------------------------------
Feature #5805: object_hexid
https://bugs.ruby-lang.org/issues/5805

Author: Thomas Sawyer
Status: Feedback
Priority: Normal
Assignee: 
Category: 
Target version: 


I would like to see #object_hexid added to Ruby to return an object's id in hexidecimal form.

By default Ruby will show this id when using #inspect.

  Object.new.inspect
  => "#<Object:0x000000023cadf0>"

I, for one, have often wanted to include this hex id when I customize an #inspect method for a class. But despite my lengthy efforts I have never been able to ensure the hex id is correct. It seems to vary a great deal depending on platform and Ruby version.

You can see the current effort at this here: https://github.com/rubyworks/facets/blob/master/lib/core/facets/kernel/object_hexid.rb But this definition is currently failing on Ruby 1.8.7 and JRuby. I have tried a number of variations, but nothing sees to work for all platforms.

My last ditch approach will be to bind Kernel#inspect InstanceMethod to the current object and extract the hex id from it's output. It should work, but it's definitely a hack. In the future I'd much rather just ask Ruby for it!




-- 
http://redmine.ruby-lang.org