Why does this not work? 12/16


#1

s = [["ham", "swiss"], ["turkey", "cheddar"], ["roast beef", "gruyere"]]
s.each do |sub_array|
sub_array.each do |y|
puts y
end
end

The above code is what I wrote to have this work. However, the syntax in the example has this:

array.each { |element| action }

Notice the difference is that there are curly braces in the example. However, if I try to submit the following code, there are errors and it dosen't let me pass.

s.each do{ |sub_array| puts sub_array}
sub_array.each do {|y| puts y}
end
end

Notice the curly braces are included in this (as they appear in the example code).


#2

One consideration might be that each operates on a block in this instance:

obj.each { |x| puts x }

There is no do in this statement.

Consder also,

obj.each do |x|
    puts x
end

Also valid, just no block. do takes the baton to begin the relay.