From: Daniel Nugent Date: 2005-09-09T02:20:18+09:00 Subject: Re: The Laziest Variable in the Whooole World How about using Thread.pass to avoid sitting in the loop while your resources could be better spent elsewhere? UPDATED SAMPLE: class Lazy #DESTROY ALL METHODS! DESTROY ALL INSTANCE METHODS! instance_methods.each { |m| undef_method m unless m =~ /^__/ } def initialize(switch = :one_eval, &block) @code_block = block @mode = switch end def method_missing(symbol, *args) if @mode == :one_eval @real_obj ||= @code_block.call @real_obj.__send__(symbol, *args) else @code_block.call().__send__(symbol, *args) end end end #Dataflow example foo = Lazy.new do while ! defined? $dfv Thread.pass end $dfv end bar = Thread.new {print foo} baz = Thread.new {sleep(3);$dfv = "Hello World, sorry I'm late"} bar.join baz.join -- -Dan Nugent