Mercurial > repos > other > SevenLanguagesInSevenWeeks
comparison 1-Ruby/truthiness-irb.output @ 11:e0a92558400f
Add some truthiness testing
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 02 Jan 2017 21:13:00 +0000 |
parents | |
children | 8d46064c9afc |
comparison
equal
deleted
inserted
replaced
10:0374ae06729e | 11:e0a92558400f |
---|---|
1 truthiness.rb(main):001:0> #! /usr/bin/env ruby | |
2 truthiness.rb(main):002:0* | |
3 truthiness.rb(main):003:0* values = [ true, false, 1, 0, -1, 'some string', '', nil ] | |
4 => [true, false, 1, 0, -1, "some string", "", nil] | |
5 truthiness.rb(main):004:0> | |
6 truthiness.rb(main):005:0* values.each { |val| | |
7 truthiness.rb(main):006:1* text = if val == nil then "nil" else "'#{val}'" end | |
8 truthiness.rb(main):007:1> puts "Val #{text} is truthy" if val | |
9 truthiness.rb(main):008:1> puts "Val #{text} is falsy" unless val | |
10 truthiness.rb(main):009:1> } | |
11 Val 'true' is truthy | |
12 Val 'false' is falsy | |
13 Val '1' is truthy | |
14 Val '0' is truthy | |
15 Val '-1' is truthy | |
16 Val 'some string' is truthy | |
17 Val '' is truthy | |
18 Val nil is falsy | |
19 => [true, false, 1, 0, -1, "some string", "", nil] | |
20 truthiness.rb(main):010:0> |