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...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: Pickaxe question: "... on the way to true Ruby mastery."
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password