Hi. I’m not seeing what I thought would happen with some eval code, here is
a sample via irb:
irb(main):001:0> class FooBar
irb(main):002:1> def baz
irb(main):003:2> puts "foobar:baz"
irb(main):006:0> f = FooBar.new
OK. So far so good, simply made a test class and ran a method from it.
irb(main):009:0> eval(“class FooBar\ndef baz\nputs ‘foobar:new
OK. So far even better. Use eval to redefine method.
irb(main):011:0> class FooBar
irb(main):012:1> def rebaz
irb(main):013:2> eval(“class FooBar\ndef baz\nputs
So far nothing seems amiss. Instead of doing eval from main script, wrote
rebaz method to do eval as instance method.
Sigh. After calling #rebaz which I thought would have changed #baz, #baz
still acts the same-- even though, except for scope/context, the eval
statement was the same exact statement as I used before, where #baz did
How can I write an instance method that will get the eval done the way I
thought it was going to work? I don’t want to eval dependent on FooBar
class, the eval might want to change a method in Gizmo or Widget class
instead. Eval just needs to happen from FooBar since that is the class
that will have the method to handle evaluation of new code. Any
Thanks for your help.