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:
- Review of common Ruby methods that accept blocks
- How to refactor your blocks into variables
- How to create methods that accept blocks
yieldandblock_given?(and other ways to work with blocks)- How to create DSLs like Rails’
Routes.draw {|map| map.resources :dogs }DSL - How to create DSLs like Rails 3’s
Routes.draw { resources :dogs }DSL - Some of the differences between
lambda,proc, andProc.new