怎么 取消 后来通过 eval 方式添加的 f(x) 方法?
class Heval
def initialize
end
def he(text)
eval(text)
end
# def inside_undef(text)
# undef :f
# end
end
str1 = 'def f(x)
return (x + 1)
end'
hh = Heval.new
hh.he(str1)
puts hh.f(2) # => 3
#hh.inside_undef('f')
#undef f #undef self.f
puts hh.respond_to?(:he) # => true
puts hh.respond_to?(:f) #=> true
__END__
How to cancel the manual 'f(x)' definition in the hh class_instance?