# \_id2ref in finalize or how get object.var from class.finalize

**URL:** <https://www.ruby-forum.com/t/id2ref-in-finalize-or-how-get-object-var-from-class-finalize/123268>\
**Category:** Ruby\
**Created:** [December 15, 2007, 6:11pm UTC](https://www.ruby-forum.com/t/id2ref-in-finalize-or-how-get-object-var-from-class-finalize/123268 "2007-12-15T18:11:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 15, 2007, 6:11pm UTC](https://www.ruby-forum.com/t/id2ref-in-finalize-or-how-get-object-var-from-class-finalize/123268/1 "2007-12-15T18:11:48Z")

</div>

#!/usr/bin/ruby1.8

include ObjectSpace

class MyClass  
attr\_reader :var  
def initialize(var)  
@var = var  
puts “from initialize: #{@var}”  
define\_finalizer(self, self.class.method(:finalize).to\_proc)  
end

def MyClass.finalize(object\_id)  
o = \_id2ref(object\_id)  
puts “from finalize: #{o.var}”  
end  
end # class Storage

o = MyClass.new(“The Value!”)  
exit 0

Hi, all.

Why lines of a code after a call of function “\_id2ref(object\_id)” are  
never carried out?  
How it is possible to get access to variables or methods of a object  
from a method of a class :finalize?
