0.0
No commit activity in last 3 years
No release in over 3 years
.naught? like ActiveSupport .blank? and nil-safe Numeric .zero?
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

naught_check¶ ↑

Why?¶ ↑

Got tired of string.empty? checks in a project blowing up on nil strings.

On a Rails project where numeric fields are declared NOT NULL, you can use ActiveSupport’s .blank? and Numeric’s .zero? instead.

But .zero? isn’t nil-safe, so if you have possibly-nil numerics you would have to require ‘andand’ and remember to do number.andand.zero? for every zero-check. Or reopen Numeric.zero? in the project and add the nil-check. Or use something like this.

Usage: ¶ ↑

require 'naught_check'
include Naught

nil.naught? => true
"".naught? => true
"    ".naught? => true
[].naught? => true
{}.naught? => true
0.naught? => true
0.00.naught? => true

.aught? does the reverse, so you don’t need the double-negative of !value.naught? (value-not-naught sounds silly)

Compared to ActiveSupport .blank?¶ ↑

In a Rails project, ActiveSupport .blank? would do almost the same thing, except for numbers:

0.blank? => false
0.naught? => true

It’s like ActiveSupport .blank? combined with a nil-safe Numeric .zero?

Copyright © 2010 Sean Miller. See LICENSE for details.