Last active
August 29, 2015 14:06
-
-
Save stujo/768c05c61394005b0c37 to your computer and use it in GitHub Desktop.
falsey_truthy - Truthyness and Falseyness in Ruby
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
def falsey_truthy string_test | |
begin | |
value = eval string_test | |
puts "#{string_test} -> '#{value}' is #{value ? 'truthy' : 'falsey'}" | |
rescue NameError => e | |
puts e | |
end | |
end | |
tests = [ | |
"true", | |
"false", | |
"nil", | |
"0", | |
"1", | |
] | |
tests.each do |string_test| | |
falsey_truthy string_test | |
end | |
def get_statement | |
print "Enter Some Ruby (return to exit):" | |
gets.chomp | |
end | |
until (line = get_statement).empty? | |
falsey_truthy line | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment