view 1-Ruby/each-irb.output @ 10:0374ae06729e

Start playing around with loop block definitions
author IBBoard <dev@ibboard.co.uk>
date Mon, 02 Jan 2017 21:01:39 +0000
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