From: Brian Candler Date: 2010-04-24T22:31:31+09:00 Subject: Re: #object_hexid Thomas Sawyer wrote: > Can anyone write a reliable Kernel#object_hexid, a method that returns > an object's id but in hex, just like Ruby's normal #inspect provides. > > My attempts seems to break depending on the version of Ruby used. Can you show the failing examples? Is the portability problem between ruby 1.8.x and 1.9.x, or are you trying to make portable with JRuby, Rubinius, MacRuby etc? Is it important that object_hexid returns the same value as reported by #inspect, or just some unique id? The obvious would be something like: >> module Kernel >> def object_hexid(o) >> o.object_id.to_s(16) >> end >> end => nil >> object_hexid("") => "3faf23593bf4" but I've not tested that on any more than MRI 1.8.7, and the hex ID is not the same as #inspect: >> class Foo; end => nil >> f = Foo.new => # >> object_hexid(f) => "3faf2358e0b4" -- Posted via http://www.ruby-forum.com/.