C
Cory Patterson
I run into this from time to time and I was wondering if there is a
cleaner way to do check that an object is not nil and also check a
property of that object.
I want to do this:
if [email protected]? and @member.is_active?
... do something ...
else
... do something else ...
end
But this obviously raises a no method error if @member is nil.
I end up having to do:
if [email protected]?
if @member.is_active?
... do something ...
else
... do something else ...
end
end
I know it isn't that much more verbose, but does ruby have a more
elegant way of handling this?
cleaner way to do check that an object is not nil and also check a
property of that object.
I want to do this:
if [email protected]? and @member.is_active?
... do something ...
else
... do something else ...
end
But this obviously raises a no method error if @member is nil.
I end up having to do:
if [email protected]?
if @member.is_active?
... do something ...
else
... do something else ...
end
end
I know it isn't that much more verbose, but does ruby have a more
elegant way of handling this?