J
James Herdman
I'm reading the last little fragment of the Pick Ax book during my exam
study breaks right now, and I'm contemplating this UnboundMethod
hotness.
Pick Ax says, "As with aliases, unbounch methods are references to the
definition of the method at the time they are created" with the example
[CODE BEGIN]
unbound_length = String.instance_method
length)
class String
def length
99
end
end
str = "cat"
str.length -> 99
bound_length = unbound_length.bind(str)
bound_length.call -> 3
[CODE END]
The first part of my question is if I can read "... are references to
the definition of the definition of the method at the time they are
created" as being equivalent to "copy of"? (My assumption is yes,
given that my unbound copy isn't altered by redefinition #length.)
The second part of my question what about the contents of
unbound_length. Does it actually contain code, or is it just a memory
location? (I.E. is there a way I can have unbound_length spit out the
code for #length?)
Thank you for your time,
James H.
study breaks right now, and I'm contemplating this UnboundMethod
hotness.
Pick Ax says, "As with aliases, unbounch methods are references to the
definition of the method at the time they are created" with the example
[CODE BEGIN]
unbound_length = String.instance_method
class String
def length
99
end
end
str = "cat"
str.length -> 99
bound_length = unbound_length.bind(str)
bound_length.call -> 3
[CODE END]
The first part of my question is if I can read "... are references to
the definition of the definition of the method at the time they are
created" as being equivalent to "copy of"? (My assumption is yes,
given that my unbound copy isn't altered by redefinition #length.)
The second part of my question what about the contents of
unbound_length. Does it actually contain code, or is it just a memory
location? (I.E. is there a way I can have unbound_length spit out the
code for #length?)
Thank you for your time,
James H.