Cool.  Thanks for explanation.

Pete

Harold wrote:
> They are both equivalent in terms of functionality.
> 
> The first is a common rails idiom:
> 
> @some_collection.collect(&:id)
> or
> @some_collection.map(&:id) #I've seen this one used more than
> collect...
> 
> The ampersand syntax is simply telling the interpreter that the symbol
> is the block parameter to the method. Internally the to_proc method of
> the symbol class is called.
> 
> Here's a reference:
> http://apidock.com/rails/Symbol/to_proc
> 
> Beware, doing @foo.map(&:id) doesn't perform as well as @foo.map { |f|
> f.id } for big numbers of foos...
> Also note that this is a Rails only feature (ie: try it on plain irb
> and it will not work).
> 
> On Mar 11, 1:35�pm, Hiro Protagonist <rails-mailing-l...@andreas-

-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to