Blocks With Parameters

You can also use parameters with yield:

# redefine the thrice method
def thrice
  yield(1)
  yield(2)
  yield(3)
end
 
# Output "Blocks are cool!" three times,
# prefix it with the count
thrice { | i |
  puts "#{i}: Blocks are cool!"
}