Get a temporary context with ‘self.dup.instance_eval’
def foo 'bar' end module M def foo 'baz' end end puts "should be 'bar': #{foo}" self.dup.instance_eval do extend(M) puts "should be 'baz': #{foo}" end puts "should be 'bar': #{foo}"
Garry Dolley worked out some interesting Ruby-fu to create a temporary execution context on the fly using self.dup.instance_eval. Any other tricks we could use this for?
August 31, 2006 at 6:18 pm
That's real hot. Real hot.