From: mental@... Date: 2006-02-20T11:43:50+09:00 Subject: Re: lazy.rb 0.9.5 -- transparent futures! Quoting "matt.smillie@gmail.com" : > If you suspected "the right thing" you'd probably be right: > > irb(main):001:0> require 'lazy' > irb(main):002:0> x = promise { 5 + 3 } > => #> > irb(main):003:0> p 3 * x > 24 > => nil It's worth noting that this only works so well because of the very nice coercion machinery Ruby has built around its numeric classes. Ruby's NUM2INT (for example) will call .to_int on the promise when FIXNUM_P fails, so everything Just Works(tm). For other cases (e.g. promises returning file handles), you may find you need to unwrap them explicitly with demand() to pass them to certain methods. Of course this is an issue only when passing promises to methods implemented in C; lazy.rb does a very good job of faking out Ruby otherwise (the boolean issue notwithstanding). -mental