annotate 1-Ruby/truthiness-irb.output @ 97:85a5e9a6ef5c

Add more notes on extracting Just/Maybe values
author IBBoard <dev@ibboard.co.uk>
date Sun, 30 Jun 2019 16:09:44 +0100
parents 8d46064c9afc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
e0a92558400f Add some truthiness testing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 truthiness.rb(main):001:0> #! /usr/bin/env ruby
e0a92558400f Add some truthiness testing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 truthiness.rb(main):002:0*
e0a92558400f Add some truthiness testing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 truthiness.rb(main):003:0* values = [ true, false, 1, 0, -1, 'some string', '', nil ]
e0a92558400f Add some truthiness testing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 => [true, false, 1, 0, -1, "some string", "", nil]
e0a92558400f Add some truthiness testing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 truthiness.rb(main):004:0>
16
8d46064c9afc Be a nice Ruby user and follow block convention for do/end vs {}
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
6 truthiness.rb(main):005:0* values.each do |val|
11
e0a92558400f Add some truthiness testing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 truthiness.rb(main):006:1* text = if val == nil then "nil" else "'#{val}'" end
e0a92558400f Add some truthiness testing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 truthiness.rb(main):007:1> puts "Val #{text} is truthy" if val
e0a92558400f Add some truthiness testing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 truthiness.rb(main):008:1> puts "Val #{text} is falsy" unless val
16
8d46064c9afc Be a nice Ruby user and follow block convention for do/end vs {}
IBBoard <dev@ibboard.co.uk>
parents: 11
diff changeset
10 truthiness.rb(main):009:1> end
11
e0a92558400f Add some truthiness testing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 Val 'true' is truthy
e0a92558400f Add some truthiness testing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 Val 'false' is falsy
e0a92558400f Add some truthiness testing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 Val '1' is truthy
e0a92558400f Add some truthiness testing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 Val '0' is truthy
e0a92558400f Add some truthiness testing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 Val '-1' is truthy
e0a92558400f Add some truthiness testing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 Val 'some string' is truthy
e0a92558400f Add some truthiness testing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 Val '' is truthy
e0a92558400f Add some truthiness testing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 Val nil is falsy
e0a92558400f Add some truthiness testing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 => [true, false, 1, 0, -1, "some string", "", nil]
e0a92558400f Add some truthiness testing
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 truthiness.rb(main):010:0>