From: Phrogz Date: 2007-11-07T13:50:02+09:00 Subject: Re: instance_eval to evaluate methods inside a block in context On Nov 6, 6:46 pm, Adam Anderson wrote: > http://pastie.caboo.se/114839 > > Can anyone tell me why this wouldn't/shouldn't/should work? I don't > want to pull out all of my hair trying to figure this out if it isn't > even possible. You can either do this: class Calculator def evaluate(&script) self.instance_eval(&script) end def two "2" end end class Foo def hi puts "hi" end def howdy me = self Calculator.new.evaluate do puts two me.hi end end end Foo.new.howdy ...or this... class Calculator def evaluate(&script) yield self end def two "2" end end class Foo def hi puts "hi" end def howdy Calculator.new.evaluate do |cal| puts cal.two hi end end end Foo.new.howdy