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

Discussion in 'Ruby' started by andrey, Dec 15, 2007.

  1. andrey

    andrey Guest

    #!/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?
     
    andrey, Dec 15, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    317
    skyofdreams
    Mar 30, 2007
  2. metaperl
    Replies:
    3
    Views:
    601
    Mark Space
    Aug 23, 2007
  3. Ara.T.Howard

    ObjectSpace::_id2ref and GC

    Ara.T.Howard, Jun 6, 2005, in forum: Ruby
    Replies:
    2
    Views:
    134
    Ara.T.Howard
    Jun 7, 2005
  4. Andrey Nikitin
    Replies:
    1
    Views:
    169
    Nobuyoshi Nakada
    Dec 16, 2007
  5. Charles Oliver Nutter

    DRbIdConv without _id2ref

    Charles Oliver Nutter, Oct 29, 2009, in forum: Ruby
    Replies:
    0
    Views:
    94
    Charles Oliver Nutter
    Oct 29, 2009
Loading...

Share This Page