# HG changeset patch # User IBBoard # Date 1483391580 0 # Node ID e0a92558400fe53d0882bcd119995943141564f3 # Parent 0374ae06729eb41874ed5d2da16d80dec2b83e8e Add some truthiness testing diff -r 0374ae06729e -r e0a92558400f 1-Ruby/truthiness-irb.output --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/1-Ruby/truthiness-irb.output Mon Jan 02 21:13:00 2017 +0000 @@ -0,0 +1,20 @@ +truthiness.rb(main):001:0> #! /usr/bin/env ruby +truthiness.rb(main):002:0* +truthiness.rb(main):003:0* values = [ true, false, 1, 0, -1, 'some string', '', nil ] +=> [true, false, 1, 0, -1, "some string", "", nil] +truthiness.rb(main):004:0> +truthiness.rb(main):005:0* values.each { |val| +truthiness.rb(main):006:1* text = if val == nil then "nil" else "'#{val}'" end +truthiness.rb(main):007:1> puts "Val #{text} is truthy" if val +truthiness.rb(main):008:1> puts "Val #{text} is falsy" unless val +truthiness.rb(main):009:1> } +Val 'true' is truthy +Val 'false' is falsy +Val '1' is truthy +Val '0' is truthy +Val '-1' is truthy +Val 'some string' is truthy +Val '' is truthy +Val nil is falsy +=> [true, false, 1, 0, -1, "some string", "", nil] +truthiness.rb(main):010:0> diff -r 0374ae06729e -r e0a92558400f 1-Ruby/truthiness-ruby.output --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/1-Ruby/truthiness-ruby.output Mon Jan 02 21:13:00 2017 +0000 @@ -0,0 +1,8 @@ +Val 'true' is truthy +Val 'false' is falsy +Val '1' is truthy +Val '0' is truthy +Val '-1' is truthy +Val 'some string' is truthy +Val '' is truthy +Val nil is falsy diff -r 0374ae06729e -r e0a92558400f 1-Ruby/truthiness.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/1-Ruby/truthiness.rb Mon Jan 02 21:13:00 2017 +0000 @@ -0,0 +1,9 @@ +#! /usr/bin/env ruby + +values = [ true, false, 1, 0, -1, 'some string', '', nil ] + +values.each { |val| + text = if val == nil then "nil" else "'#{val}'" end + puts "Val #{text} is truthy" if val + puts "Val #{text} is falsy" unless val +}