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

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -