view 1-Ruby/truthiness-irb.output @ 93:39084e2b8744

Add a function for word-aware text wrapping Potentially hugely inefficient because we iterate through the string character by character, but then splitting it first and iterating over words still needs to iterate over the string to know where to split.
author IBBoard <dev@ibboard.co.uk>
date Tue, 18 Jun 2019 21:05:00 +0100
parents 8d46064c9afc
children
line wrap: on
line source

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 do |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> end
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>