Created
September 10, 2015 21:01
-
-
Save gilomen2/51777e5171f9eb68ee4d to your computer and use it in GitHub Desktop.
Unexpected true/false behavior using defined?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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