From: MenTaLguY Date: 2005-11-06T02:14:23+09:00 Subject: Re: [ANN] lazy.rb --=-ZlhVJ8JMal4ZXqCk8y/T Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Sat, 2005-11-05 at 11:46 +0900, Pit Capitain wrote: > MenTaLguY schrieb: > > ... > > Same problem in both cases, basically. >=20 > Here's another implementation that doesn't have these problems: >=20 > module Lazy #:nodoc: all > class Thunk > instance_methods.each { |m| undef_method m unless m =3D~ /^__/ } > def initialize( &computation ) > @computation =3D computation > end > def method_missing( *args, &block ) > ( @result ||=3D @computation.call( self ) ).send( *args, &block = ) > end > end > end Hmm, I can adapt this, I think. Thanks. It does have a few problems as written; e.g.: 1. since @computation isn't set to nil after being run, the closure can't get garbage collected until the thunk is 2. the computation will get run multiple times if its result is nil or false 3. There's no way to unwrap the value from the thunk But I think you got me over the hump. Look for another lazy.rb release soonish. -mental --=-ZlhVJ8JMal4ZXqCk8y/T Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQBDbOiDcUNIGiXCc4MRAucwAJ9lASHEbQdcR/HyHQK2cRyErlKNaACgnCOv nCqM5fXZu36bNdeIy/bq8wk= =Do0h -----END PGP SIGNATURE----- --=-ZlhVJ8JMal4ZXqCk8y/T--