Phrogz
12/11/2007 7:40:00 PM
On Dec 11, 11:56 am, Andrew Stone <stoneli...@gmail.com> wrote:
> Note: parts of this message were removed by the gateway to make it a legal Usenet post.
>
> if not my_var.nil?
>
> Thanks Justin. I should have been more clear with the usage.
>
> def should_this_be_done?
> am_I_sure? && my_object.var && !my_object.var.nil?
> end
>
> I just think it would read better if the last test was my_object.var.exists?
1) No such opposite-of-nil? method exists. If you want it, add it.
class Object
def exists?
true
end
end
class NilClass
def exists?
false
end
end
# up to you if you want this for FalseClass, too
2) In the particular example above (which I realize is just an
example) you could write that as:
def should_this_by_done?
am_I_sure? unless !my_object || my_object.var.nil?
end
But, of course, that just moves the negation.