Why can’t I call Enumerable#reduce(sym) without parentheses like the following?
>> [1, 2, 3].reduce :+
?>
While using parentheses results in this:
>> [1, 2, 3].reduce(:+)
=> 6
Am I accidentally calling Enumerable#reduce {| memo, obj | block } instead?
Furthermore, why does this happen?
>> [1, 2, 3].reduce &:+
?> ^C
>> [1, 2, 3].reduce(&:+)
=> 6
Thanks a lot!
That seems to be an error in IRb’s parser. It works just fine if you try it in Pry, or on the commandline or in a file:
Basically, IRb gets confused, thinks the
+is a binary operator and is waiting for the second operand.