view 1-Ruby/each-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 369e7cdf3ddf
children
line wrap: on
line source

each.rb(main):001:0> #! /usr/bin/env ruby
each.rb(main):002:0* 
each.rb(main):003:0* # Declare an array of strings (like many languages, 
each.rb(main):004:0* # single quotes are *not* interpolated)
each.rb(main):005:0* properties = [ 'object oriented', 'duck typed', 'productive', 'fun']
=> ["object oriented", "duck typed", "productive", "fun"]
each.rb(main):006:0> 
each.rb(main):007:0* # Call the Each function with a code block.
each.rb(main):008:0* # Name each parameter "property" and output it
each.rb(main):009:0* # "puts" is like printf - it will *put* a *s*tring to the screen
each.rb(main):010:0* properties.each { | property | puts "Ruby is #{property}." }
Ruby is object oriented.
Ruby is duck typed.
Ruby is productive.
Ruby is fun.
=> ["object oriented", "duck typed", "productive", "fun"]
each.rb(main):011:0> 
each.rb(main):012:0* # Note: irb output after properties.each is content of properties
each.rb(main):013:0* 
each.rb(main):013:0> 
=> nil