abaldwin99 abaldwin99 - 6 months ago 19
Ruby Question

Can self ever be false or nil?

Can

self
ever evaluate to false or nil?

For example...

class FooBar

...

def check_this
self && check_something_else
end
end


Is the
self &&
in this conditional necessary?

Answer

Yes. Remember everything in Ruby is an object so self is falsy for false and nil:

nil.instance_eval { self }  # => nil
false.instance_eval { self }  # => false