Transparent Nil

bklippstein.github.com/transparent_nil/frames.html

nil values can be quite annoying. Although it is a nice error indicator but you’re source code gets ugly with too many conditional statements that handle the nil case.   TransparentNil defines some methods for nil so nil values behave like any other object. Most of them return just nil, but some are different:

nil.dup
=> nil

nil[2]
=> nil

nil.empty?
=> true

nil << [element] 
=> [[element]]

nil.size
=> 0

nil.split(//)
=> []

nil <=> 1
=> nil

Think nil als “nothing”. You can ask for nil if you need to, but you don’t have to do it so often.

The Kyanite gem extends the usage of nil.

Usage

require 'transparent_nil'

More Info

Disclaimer

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.