From: Brian Candler Date: 2010-10-15T04:16:34+09:00 Subject: Re: from a String. Huw Taylor wrote in post #950237: > If I were to have this: > > class Hew > def initialize(string) > @string = string > end > def other_method > end > end > > a = Hew.new("Broown Cew") > => # > > b = a.to_s > => "#" > > My question is: Is there anyway to get the class (and its info) from b > (i.e what is now a string)? Maybe you're looking for ObjectSpace._id2ref Unfortunately, the hex pointer shown by #inspect doesn't always map directly to the object's object_id, and I think the algorithm to map it varies with the version of ruby you're running :-( But here in principle is how you recover a reference to the object: >> RUBY_DESCRIPTION => "ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]" >> a = Hew.new("Broown Cew") => # >> a.object_id.to_s(16) => "3fbdb750a974" >> (a.object_id << 1).to_s(16) => "7f7b6ea152e8" >> b = ObjectSpace._id2ref(Integer("0x7f7b6ea152e8") >> 1) => # >> a.eql?(b) => true -- Posted via http://www.ruby-forum.com/.