You’ve already seen how to use a block to iterate over an array. In the next example (also in 4blocks.rb), I use one block to iterate over an array of strings, assigning each string in turn to the block variable s
. A second block is then passed to the caps
method in order to capitalize the string:
["hello","good day","how do you do"].each{ |s| caps( s ){ |x| x.capitalize! puts( x ) } }
This results in the following output:
Hello Good day How do you do
3.137.223.10