Quick question, I've run across this select(&:even)
syntax a few times, and I understand it for the most part except for one thing:
The &
symbol, to me, is what makes the method name, well a method name. I don't understand why a symbol syntax is needed to define even. In a short example:
arr = [1,2,3,4,5]
puts arr.select(&:even?)
correctly selects and prints all the even numbers but,
arr = [1,2,3,4,5]
puts arr.select(&even?)
produces:
Untitled 3.rb:2:in <main>: undefined method even? for main:Object (NoMethodError)
Can anyone help me understand the necessity of using a :
symbol?