# I don't understand the reject syntax {|a|

**URL:** <https://www.ruby-forum.com/t/i-dont-understand-the-reject-syntax-a/139559>\
**Category:** Rails\
**Created:** [June 4, 2008, 11:31pm UTC](https://www.ruby-forum.com/t/i-dont-understand-the-reject-syntax-a/139559 "2008-06-04T23:31:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![victordeandres](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/8c91f0/32.png) [@victordeandres](https://www.ruby-forum.com/u/victordeandres)\
**Post date:** [June 4, 2008, 11:31pm UTC](https://www.ruby-forum.com/t/i-dont-understand-the-reject-syntax-a/139559/1 "2008-06-04T23:31:26Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![victordeandres](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/8c91f0/32.png) [@victordeandres](https://www.ruby-forum.com/u/victordeandres)\
**Post date:** [June 4, 2008, 11:59pm UTC](https://www.ruby-forum.com/t/i-dont-understand-the-reject-syntax-a/139559/2 "2008-06-04T23:59:38Z")

</div>

On Jun 4, 10:31 pm, Victor D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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

---

<div class="post-metadata">

**Author:** ![victordeandres](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/8c91f0/32.png) [@victordeandres](https://www.ruby-forum.com/u/victordeandres)\
**Post date:** [June 7, 2008, 1:25am UTC](https://www.ruby-forum.com/t/i-dont-understand-the-reject-syntax-a/139559/3 "2008-06-07T01:25:47Z")

</div>

On Wed, Jun 4, 2008 at 5:57 PM, Frederick C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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]

## Is (quite a bit?) clearer.

Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)
