DEV Community

Discussion on: Post an Elegant Code Snippet You Love.

Collapse
 
edwardloveall profile image
Edward Loveall • Edited

I've heard it called a "symbol to proc" or "symbol proc" and it's short for this:

.select { |foo| foo.even? }
# same as 
.select(&:even?)
Enter fullscreen mode Exit fullscreen mode

It's calling the method even? on each number passed in. Behind the scenes it creates a proc and then passes in each number. Here are the ruby docs for Symbol#to_proc and here's a pretty decent break down of symbol to proc.