T
Trans
What's the best way to avoid the classic method_added/define_method
infinite loop?
class X
def self.method_added(name)
p name
define_method(name)
# do something else
end
end
def foo; end
end
This will, of course, print "foo" forever.
As an aside, anyone else think method_added should also receive a
block of the method definition? E.g. this would be a "push" (less the
infinite loop issue):
def self.method_added(name, &block)
define_method(name, &block)
end
Thanks!
T.
infinite loop?
class X
def self.method_added(name)
p name
define_method(name)
# do something else
end
end
def foo; end
end
This will, of course, print "foo" forever.
As an aside, anyone else think method_added should also receive a
block of the method definition? E.g. this would be a "push" (less the
infinite loop issue):
def self.method_added(name, &block)
define_method(name, &block)
end
Thanks!
T.