I have the following line of code, anyone could decypher this syntax ? @teams.reject {|a| a.sport.id != @sport.id }.sort { |a,b| b.points <=> a.points } [0..2] -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 4, 10:31 pm, Victor Dias <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have the following line of code, anyone could decypher this syntax ? > > @teams.reject {|a| a.sport.id != @sport.id }.sort { |a,b| b.points <=> > a.points } [0..2]take @teams, remove all teams where sport.id is not @sport.id, then sort them by points (descending) and return the top 3. Or in other words, return the top 3 teams for the sport designated by @sport Fred> -- > Posted viahttp://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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Wed, Jun 4, 2008 at 5:57 PM, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On Jun 4, 10:31 pm, Victor Dias <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > I have the following line of code, anyone could decypher this syntax ? > > > > @teams.reject {|a| a.sport.id != @sport.id }.sort { |a,b| b.points <=> > > a.points } [0..2] > > take @teams, remove all teams where sport.id is not @sport.id, then > sort them by points (descending) and return the top 3. > Or in other words, return the top 3 teams for the sport designated by > @sport >Yes, and I feel the duty to suggest that the equivalent @teams.select {|a| a.sport.id == @sport.id }.sort { |a,b| b.points <=> a.points } [0..2] Is (quite a bit?) clearer. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---