J
Juston Davies
I had a quick question about something I had read in a book "The Ruby
Way." The author talks about different ways to dynamically define
methods during runtime using something similar to the snippet below.
def define_method (name, &array)
self.class.send
define_method, name,&array)
end
This opens up the scope of a given class so any other class could add
methods on the fly. My question is that if I were to insert this code
into a parent and then invoke it on a child would the new method be
defined within the scope of the child or the parent? I'm concerned
that this might result in adding methods into all the children rather
than just the desired one. Let me know what you think. Thanks in
advance!
Way." The author talks about different ways to dynamically define
methods during runtime using something similar to the snippet below.
def define_method (name, &array)
self.class.send
end
This opens up the scope of a given class so any other class could add
methods on the fly. My question is that if I were to insert this code
into a parent and then invoke it on a child would the new method be
defined within the scope of the child or the parent? I'm concerned
that this might result in adding methods into all the children rather
than just the desired one. Let me know what you think. Thanks in
advance!