Skip to content

Instantly share code, notes, and snippets.

@stujo
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stujo/768c05c61394005b0c37 to your computer and use it in GitHub Desktop.
Save stujo/768c05c61394005b0c37 to your computer and use it in GitHub Desktop.
falsey_truthy - Truthyness and Falseyness in Ruby
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