Hi –
On Tue, 21 Aug 2007, Phlip wrote:
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).
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? %>
You don’t have a name!
<% end %>
I’d find it very hard to interpret this:
<% unless name.relevant? %>
You don’t have a name!
<% 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
–