2002: Dave Thomas starts to further work up nil.empty?. Opposition brews. (Note that the possibility of nil becoming an Enumerable is kicked around!)
2004:Zero is true … whoda thunk? thread delves in and out of the character of nil, 0, "" and so on. However, the discussion really revolves around whether zero could be treated as false in a future Ruby incarnation.
In all, the two major points of backlash have been:
Naming the thing. Some feel that empty? implies a container. A container which isn’t there for nil and 0. Another suggestion was vapid? but, uh, no.
That there is no case in which 0 should be grouped with nil and "". I suppose many people are more commonly looking for "0" to belong to this group as well. Which means you have to use .to_i.zero?. Very similar to .to_s.empty?.
I’m thinking Object#blank? is a good solution. The name doesn’t imply a container. It implies valuelessness, which is what we are testing for.
This reduces the common case of:
if venue['neighborhood'].to_s.empty?
To:
if venue['neighborhood'].blank?
I’ve grouped 0 in there as well. It’s useful for YAML. Since YAML loads types naturally, you rarely run into a string like "0". And since I’m calling zero?, it works for floats as well.
Given this YAML invoice:
sku: BSK115
price: 15.60
tax: 0.00
total: 15.60
I can easily check the tax, covering the case in which the tax is completely left out.
print "Tax-free" if invoice['tax'].blank?
So, what do you think? Worthwhile RCR? Am I off on the name? Has our time come for this at last?
I’ve just submitted this proposal as RCR 295, which also weighs the possibility of a to_b conversion. This may kill the RCR, but I’d like to vote and ultimately find the best solution. I still prefer Object#blank?. But either is a move ahead.