Skip to content

Instantly share code, notes, and snippets.

@avit
Last active December 11, 2015 07:58
Show Gist options
  • Save avit/4569725 to your computer and use it in GitHub Desktop.
Save avit/4569725 to your computer and use it in GitHub Desktop.
Wondering why a direct comparison using "if" passes when the value is falsy.
class NullObject
def true?; false end
def false?; true end
def nil?; true end
def blank?; true end
def present?; false end
def empty?; true end
def to_s(*); "" end
def !; true end
def method_missing(*args, &block)
self
end
def to_value
nil
end
end
if NullObject.new
puts "I should not be here, isn't it falsy?"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment