From: Paul Brannan Date: 2004-05-05T05:51:09+09:00 Subject: Re: Lazy evaluation On Sat, May 01, 2004 at 03:45:04AM +0900, Michael Neumann wrote: > Any comments or suggestions? I'm not suggesting that anyone actually do this, but I have a lazily- evaluated object that looks something like this: class LazyFoo def method_missing(*args, &block) $foo = Foo.new $foo.__send__(*args, &block) end Kernel.instance_methods.each do |m| next if m == '__send__' next if m == '__id__' eval <<-END def #{m}(*args, &block) method_missing(:#{m}, *args, &block) end END end end $foo = LazyFoo.new Obviously this only works with global variables, and it doesn't work if you pass the variable around. IMO Object#become is a much cleaner solution, and while there are some limitations with every Object#become I've seen thus far for Ruby 1.6 and 1.8, I hope that we will have a clean implementation of Object#become in a future version of Ruby, so that we can have nice lazy evaluation without using delegates. Paul