On 28.01.2007 19:18, Thomas Hafner wrote:
> Aaron Patterson <aaron_patterson / speakeasy.net> wrote/schrieb <20070128190516.GA5600 / eviladmins.lan>:
> 
>> def f(oi)
>>   g = [false, nil]
>>   ObjectSpace.each_object { |a|
>>     g = [true, a] if a.object_id == oi
>>   }
>>   g
>> end
> 
> Thanks, but:
> 4.object_id
> => 9
> f(9)
> => [false, nil]
> I'd expect [true,4], instead.

You don't want to use #each_object for this - this is way to 
inefficient.  You want #_id2ref:

irb(main):006:0> ObjectSpace._id2ref 4.object_id
=> 4
irb(main):007:0> ObjectSpace._id2ref "foo".object_id
=> "foo"

Kind regards

	robert