In honor of the Ruby Why Day, I was inspired to dabble in Ruby Blocks after being reading “Fox In Socks” multiple times to my children before bed. For all of you parents out there that have read the book many, many times while your children are giggling at your pronunciation difficulties, I am sure this bit will be familiar:

def fox_in_socks_blocks
  chicks_bricks = ["Chicks","bricks","blocks","clocks"]
  yield chicks_bricks[0..1]
  yield [chicks_bricks[0],chicks_bricks[2]]
  yield chicks_bricks
end

fox_in_socks_blocks do |sillywords|
  puts "#{sillywords[0]} with #{sillywords[1]} come." if sillywords.size < 3
  puts "#{sillywords[0]} with #{sillywords[1]} and #{sillywords[2]} and #{sillywords[3]} come." if sillywords.size >= 3
end

That’s right - the output is: Chicks with bricks come. Chicks with blocks come. Chicks with bricks and blocks and clocks come.

Is your tongue numb?

Happy Why Day!