From: Daniel Nugent Date: 2006-02-24T10:08:39+09:00 Subject: Re: lazy.rb 0.9.5 -- transparent futures! I don't think I understand what'sgoing on th... oh wait. I see. both table_name and name are pointing to "CUSTOMERS" and then only table_name is pointing to "MONKEYS" Yes, see, the thing that's important to consider is that I'm dumb. *tries out Mental's examples, figures out how they work* ... Woah, that's some powerful ju-ju. Maybe I should go and futz with GhostWriter again anyhow... On 2/23/06, Jim Weirich wrote: > Daniel Nugent wrote: > > table_name = "CUSTOMERS" > > x = promise {table_name.dup} > > table_name = "MONKEYS" > > puts x > > =>"CUSTOMERS" > > > > Would avoid the problem. Though it's good to point out that you > > likely want to avoid changing the state of any variable that's > > captured by a promise closure (unless of course you plan on exploiting > > just that). > > Hmmm ... I just tried it and got "MONKEYS" for the result. It makes > sense becase by the time table_name is dup'ed in the promise, it has > already been modified. > > This would do it: > > def table_promise(name) > promise { name } > end > > table_name = "CUSTOMERS" > x = table_promise(table_name) > table_name = "MONKEYS" > puts x # => "CUSTOMERS" > > -- > -- Jim Weirich > > > > -- > Posted via http://www.ruby-forum.com/. > > -- -Dan Nugent