Mercurial > repos > other > SevenLanguagesInSevenWeeks
annotate 1-Ruby/truthiness-irb.output @ 71:32f018861e36
Add Day 1 Erlang content
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 02 Feb 2018 20:38:36 +0000 |
parents | 8d46064c9afc |
children |
rev | line source |
---|---|
11 | 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> | |
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 | 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 | |
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 | 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> |