[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Pickaxe question: "... on the way to true Ruby mastery."

Andreas S

1/3/2007 7:28:00 AM

Hi Jeff,

I think this is the intention of the code, that the assignment function is
called precisely only once and it is generic, in a sense that it can store
any value, including nil and 'false'

Now, you are correct that what you describe there is the behavior of the
code 'to be replaced' by 'once'. The intention is the same, namely, the
first call returned value should be cached and the subsequence call should
just return that cached value, never to assigned again.

The original code, however, has drawback: if the cached value is nil or
'false', the assignment will be made again. The 'once' code is an
improvement over the original code that 1) it's more elegant, 2) and it
trully assigns only once, even with nil or 'false' cached value.

-andre

_________________________________________________________________
Type your favorite song.  Get a customized station.  Try MSN Radio powered
by Pandora. http://radio.msn.com/?icid=T002M...