Skip to content

Instantly share code, notes, and snippets.

@gilomen2
Created September 10, 2015 21:01
Show Gist options
  • Save gilomen2/51777e5171f9eb68ee4d to your computer and use it in GitHub Desktop.
Save gilomen2/51777e5171f9eb68ee4d to your computer and use it in GitHub Desktop.
Unexpected true/false behavior using defined?
THING = "thing_one"
puts THING
if defined? THING
puts "defined? THING is truthy"
else
puts "defined? THING is falsey"
end
if THING == "thing_two"
puts "THING == \"thing_two\" is truthy"
else
puts "THING == \"thing_two\" is falsey"
end
# why is this truthy?
if defined? THING && THING == "thing_two"
puts "defined? THING && THING == \"thing_two\" is truthy"
else
puts "defined? THING && THING == \"thing_two\" is falsey"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment