1

Possible Duplicate:
What does map(&:name) mean in Ruby?

I know, that i can sort an array of objects by specific field with following code:

articles = articles.sort_by(&:date)

What actually does this magical statement ?

&:date

What is going here ?

Community
  • 1
  • 1
AntonAL
  • 16,692
  • 21
  • 80
  • 114
  • 1
    This is a duplicate of no less than 12 other questions that have already been asked and answered here on StackOverflow: [Understanding \[ClassOne, ClassTwo\].each\(&:my_method\)](http://StackOverflow.Com/q/99318/), [What does `map(&:name)` mean in Ruby?](http://StackOverflow.Com/q/1217088/), [What exactly is is this in ruby: `&:capitalize`](http://StackOverflow.Com/q/1792683/), [Ruby/Ruby on Rails ampersand colon shortcut](http://StackOverflow.Com/q/1961030/), [Ruby : `&:symbol` syntax](http://StackOverflow.Com/q/2096975/), … – Jörg W Mittag Apr 11 '11 at 11:27
  • … [What is this `&:last` Ruby Construct Called?](http://StackOverflow.Com/q/2211751/), [What do you call the `&:` operator in Ruby?](http://StackOverflow.Com/q/2259775/), [What does `map(&:name)` do in this Ruby code?](http://StackOverflow.Com/q/2388337/), [What are `:+` and `&+` in ruby?](http://StackOverflow.Com/q/2697024/), [`&:views_count` in `Post.published.collect(&:views_count)`](http://StackOverflow.Com/q/3888044/), [Ruby Proc Syntax](http://StackOverflow.Com/q/4512587/), [How does “`(1..4).inject(&:+)`” work in Ruby](http://StackOverflow.Com/q/5003257/). – Jörg W Mittag Apr 11 '11 at 11:27
  • Let's see if we can close all those other questions as well! – Andrew Grimm Apr 11 '11 at 12:22
  • 12 duplicates, 12 votes in a day ... I think this is the beginning of a beautiful friendship. – Andrew Grimm Apr 11 '11 at 12:56

0 Answers0