In Ruby, some objects are passed by value and some by reference. In case, we want to pass by reference some object which by default gets passed by value, we can just use the id value of the object in Ruby's memory, i.e. the object space. The id can be obtained as follows.
Here is how pass by reference would work using object id values.
Such use should be highly improbable and might even turn out to be bad practice; but sometimes we just want to do things for the heck of it.
some_object = "some intialization"
some_object.object_id
Here is how pass by reference would work using object id values.
def caller
blah = "blahblueblah"
callee(blah.object_id)
end
def callee(object_id)
puts ObjectSpace._id2ref(doc.object_id)
end
Such use should be highly improbable and might even turn out to be bad practice; but sometimes we just want to do things for the heck of it.
No comments:
Post a Comment