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]
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]
On Jun 4, 10:31 pm, Victor D. [email protected]
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
On Wed, Jun 4, 2008 at 5:57 PM, Frederick C.
[email protected]
wrote:
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]
Rick DeNatale
My blog on Ruby
http://talklikeaduck.denhaven2.com/
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs