Hi --
blank? is negative.
I disagree; I think it's a positive measure. It just happens to be a
positive measure of emptiness. I put it in the same category as nil?,
zero?, and empty?, all of which are positive tests for emptiness (or
whatever the best master term is).
I like positive booleans:
module Relevate
def relevant?
return ! blank?
end
def relevance
return to_s if relevant?
end
end
I'm not sold on the concept of an object's "relevance" being coupled
to a string representation. At least for me, "relevance" doesn't
denote or connote anything along those lines.
# ERGO dry these up
class String
def blank?
return strip.size == 0
end
end
class NilClass
def blank?; true; end
end
The original versions are essentially the same as those already,
though the original String#blank? does lazy creation of the stripped
version of the string:
class NilClass #:nodoc:
def blank?
true
end
end
class String #:nodoc:
def blank?
empty? || strip.empty?
end
end
So the repetition of empty? isn't gratuitous.
NilClass.send :include, Relevate
String .send :include, Relevate
Use .relevant? as the negation of .blank?
What if an empty string is relevant, in the sense of being of interest
to the programming logic?
<% if name.blank? %>
<p>You don't have a name!</p>
<% end %>
I'd find it very hard to interpret this:
<% unless name.relevant? %>
<p>You don't have a name!</p>
<% end %>
Use .relevance to avoid this:
x = y.relevant? ? y.to_s : default
You can just say:
x = y.relevance || default
Again, I would never pick up on the fact that the "relevance" of y
means a string representation. Maybe "populated?" would be better.
David