| Path: | lib/once.rb |
| Last Update: | Sat Jan 27 19:33:13 -0500 2007 |
Do something only once. Called this way:
once('variable-name') { block }
*variable-name* is a string. The corresponding variable is referenced within the block‘s binding using eval().
If the variable doesn‘t exist, or if it‘s false or nil:
The block is executed.
The variable is set to true, within the block's binding.
True is returned.
If the variable is true:
False is returned.
Although this will by default create a simple boolean, more complex variables such as object.method calls, array and hash references work fine. I‘ve used it effectively with 2-dimensional hashes.
Copyright (C) 2005 Bruce Perens <bruce@perens.com> Distributable under the same license as Ruby.
Do something only once. Called this way:
once('variable-name') { block }
*variable-name* is a string. The corresponding variable is referenced within the block‘s binding using eval().
If the variable doesn‘t exist, or if it‘s false or nil:
The block is executed.
The variable is set to true, within the block's binding.
True is returned.
If the variable is true:
False is returned.
Although this will by default create a simple boolean, more complex variables such as object.method calls, array and hash references work fine. I‘ve used it effectively with 2-dimensional hashes.
Copyright (C) 2005 Bruce Perens <bruce@perens.com> Distributable under the same license as Ruby.