Christophe,
The "&:new_record?" is a Rails idiom. In this example it is a shortcut
for...
tasks.reject{|t| t.new_record?}.each do |task|
Anthony Crumley
On Thu, Apr 8, 2010 at 10:08 AM, Christophe Decaux <
[email protected]> wrote:
> Hi there,
>
> I've been investigating the railscasts episodes which talk about complex
> forms and I ran across this notation in the example code provided in part 3
> of the episode.
>
> at some point in a model method, there is this line:
>
> tasks.reject(&:new_record?).each do |task|
>
> I have no problem with the ".each do..." stuff, I guess that "reject" is
> quite the opposite of find but I quite don't understand the "&:new_record?"
> notation
> What is the purpose of the &
> Is it some sort of Ruby idiom
>
> I have the feeling that it should read "find any task object that is not
> new" (i.e. created but not saved)
>
> How would you customize it to achieve this goal :
>
> Find the last task object (sorted by id's) that is not new
>
> Thanks a lot in advance
> Christophe
>
> --
> 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]<rubyonrails-talk%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
--
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.