Having Fun with Ruby Blocks

To view this screencast, add it to your cart and checkout. You can buy this screencast for any price, including FREE!

Blocks are a very unique and important part of Ruby’s syntax.

 1 ['Rover', 'Spot', 'Rex'].each do |dog_name|
 2   puts "The dog's name is #{ dog_name }"
 3 end
 4 
 5 >> ['Rover', 'Spot', 'Rex'].map {|name| name.upcase }
 6 => ['ROVER', 'SPOT', 'REX']
 7 
 8 >> a_block = lambda {|name| name.upcase }
 9 >> ['Rover', 'Spot', 'Rex'].map &:a_block
10 => ['ROVER', 'SPOT', 'REX']

In this screencast, we cover: