ruby - What really do ObjectSpace._id2ref method return? -
i have example:
def puts "hello" end r = objectspace._id2ref(a.object_id) # r reference r == #=> true r #=> nil why impossible call a r?
you can't method references name that. a nil in example when pass #_id2ref, because ruby trying find local variable named a.
a.class => nil r.class => nil thus, r == a because both r , a nil.
however, can reference #a #method:
> r = objectspace._id2ref(method(:a).object_id) => #<method: object#a> > r == method(:a) => true > r.call hello => nil
Comments
Post a Comment