Issue #5805 has been reported by Thomas Sawyer.

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

Author: Thomas Sawyer
Status: Open
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