tr do
td @item.foo
end unless (@item.foo.nil? || @item.foo.empty?)
Is there a way to combine these two OR clauses into one?
tr do
td @item.foo
end unless @item.foo.nil_or_empty?
Thanks,
Joe
--
what science finds to be nonexistent, we must accept as nonexistent; but what
science merely does not find is a completely different matter... it is quite
clear that there are many, many mysterious things.
- h.h. the 14th dalai lama
transfer_four_million_euros_to_swiss_account
rescue
hours_of_debugging?
ensure
modify_builtins_with_care!
end
end
-a
···
On Sat, 9 Sep 2006, Marshall T. Vandegrift wrote:
ara.t.howard@noaa.gov writes:
tr{ tr @item.foo } unless @item.foo.to_s.empty?
It makes sense to me that
object.to_s.empty? # => true
should imply
object.empty? # => true
So why not just do
class NilClass
def empty?; true; end
end
?
-Marshall
--
what science finds to be nonexistent, we must accept as nonexistent; but what
science merely does not find is a completely different matter... it is quite
clear that there are many, many mysterious things.
- h.h. the 14th dalai lama
Doesn't to me. nil is not a container, and it should not be treated as one. A string is a container (contains a sequence of characters) and can therefore be empty. The fact that one, arbitrary string representation of nil happens to be the empty string doesn't mean that nil is empty. (This is also why I disklike rails's #blank?, but at least it's named something different.)
···
On Sep 9, 2006, at 10:37 AM, Marshall T. Vandegrift wrote:
On Sat, 09 Sep 2006 06:53:59 +0900, Joel VanderWerf wrote:
Matthew Moss wrote:
tr do
td @item.foo
end unless (@item.foo.nil? || @item.foo.empty?)
Is there a way to combine these two OR clauses into one?
Define a method on the class of foo?
class Foo
^^^
Object
def nil_or_empty?
return nil? || empty?
end
end
Otherwise it won't be defined when foo==nil.
--
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/