From: Florian Frank Date: 2006-07-31T00:05:09+09:00 Subject: Re: what is the scope of this object Robert Klemme wrote: > It's a local variable that goes out of scope when the class body is > closed. The fact that you can access it via ObjectSpace does not > proove much. The instance is likely not yet garbage collected when > you start ObjectSpace.each_object. Also note, that it's dangerous to > rely on IRB when it comes to local variables and such as IRB behaves > slightly different than the Ruby interpreter due to the line by line > mode. First I thought the same. But running the following (even without IRB) still finds the object: class A def secret;"you found me";end end class BlackHole A.new nil end GC.start ObjectSpace.each_object(){|obj| $found=obj if obj.respond_to? :secret } p $found # => # p $found.secret # => "you found me" v = [ RUBY_PLATFORM, RUBY_VERSION, RUBY_RELEASE_DATE ] * ' ' p v # => "i686-linux 1.8.4 2005-12-24" Is this a bug? -- Florian Frank