Ruby Symbols Syntax

Viewed 32
p [1,2,3].map(&:abs)  
p [1,2,3].map(:abs)  
p [1,2,3].reduce(&:gcd)  
p [1,2,3].reduce(:gcd)  

Can someone pls explain why line 2 will throw an error, but not line 4.

1 Answers

This isn't a general syntactic thing related to Symbol or Symbol#&. It's a special case built into the implementation of Enumerable#reduce.

Related