July 2011
Intermediate to advanced
400 pages
8h 46m
English
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
Read now
Unlock full access