When parentheses are important:
So, braces have higher precedence over do/end blocks. According to Pickaxe, when calling a method with no parentheses, the braces will be applied to the last method parameter, do will be applied to the invocation.
A Very Contrived Example:
def string_to_integer
if block_given?
yield.to_i
else
0
end
end
a = [1,2,3]
A) a.inject string_to_integer { ’5′ } do |i,sum| i + sum end => 11
B) a.inject string_to_integer { |i,sum| i + sum } => undefined method error
C) a.inject string_to_integer do |i,sum| i + sum end => 6
in A, the first brace is sent to the string_to_integer method
in B, the same happens, but the block was actually meant for inject
in C it works as intended.
Just food for thought.