# A sort question

**URL:** <https://www.ruby-forum.com/t/a-sort-question/125125>\
**Category:** Rails\
**Created:** [January 5, 2008, 9:18pm UTC](https://www.ruby-forum.com/t/a-sort-question/125125 "2008-01-05T21:18:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![extempore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6bbea6/32.png) [@extempore](https://www.ruby-forum.com/u/extempore)\
**Post date:** [January 5, 2008, 9:18pm UTC](https://www.ruby-forum.com/t/a-sort-question/125125/1 "2008-01-05T21:18:27Z")

</div>

dear I have this list  
@@spelers = Speler.new(‘Jan Janssens’, ‘M’, 5, ‘SR’),Speler.new(‘Leen  
Leniksen’, ‘V’, 7),  
Speler.new(‘Piet Pieters’, ‘M’, 3), Speler.new(‘Els Elsenbocht’,  
‘V’, 1, ‘J’),  
Speler.new(‘Karel Carlsen’, ‘M’, 8), Speler.new(‘Mieke Mieters’,  
‘V’, 9, ‘P’),  
Speler.new(‘John Johanses’, ‘M’, 5, ‘J’), Speler.new(‘Veerle  
Veldsen’, ‘V’, 3)

and I need to sort them into a top three for every mail and female in  
this list  
the M is for mail the V for female.

I have a def gender? geslacht  
@geslacht = geslacht  
end  
I know you could solve it like the example below however I would like to  
do it with an IF structure or with a bubble sort but not able to figure  
this out  
could someone help me out here and give me an example on how to solve  
this

def self.top3 geslacht  
per\_geslacht(geslacht).sort\_by { |x| x.score  
}.to\_a.slice(-3,3).reverse  
end

when it’s an if structure  
I should start somehow with  
if speler.score1 \> speler.score2  
print speler.score1  
else  
print speler.score2  
but after this I,m lost since I don’t know how to difference the first  
person from the second  
thanks for your help and feedback

Paul

---

<div class="post-metadata">

**Author:** ![extempore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6bbea6/32.png) [@extempore](https://www.ruby-forum.com/u/extempore)\
**Post date:** [January 6, 2008, 7:33am UTC](https://www.ruby-forum.com/t/a-sort-question/125125/2 "2008-01-06T07:33:40Z")

</div>

Paul P. wrote:

> I know you could solve it like the example below however I would like to  
> do it with an IF structure or with a bubble sort but not able to figure  
> this out

Why? Is it slow? Does it not do exactly what you want?

---

<div class="post-metadata">

**Author:** ![extempore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6bbea6/32.png) [@extempore](https://www.ruby-forum.com/u/extempore)\
**Post date:** [January 6, 2008, 8:22am UTC](https://www.ruby-forum.com/t/a-sort-question/125125/3 "2008-01-06T08:22:53Z")

</div>

not that it’s slow but I would like to achieve the same with the if  
structure and was wondering how this can be done if someone could help  
me with an example it would be much appreciated

Daniel W. wrote:

> Paul P. wrote:
> 
> > I know you could solve it like the example below however I would like to  
> > do it with an IF structure or with a bubble sort but not able to figure  
> > this out
> 
> Why? Is it slow? Does it not do exactly what you want?

---

<div class="post-metadata">

**Author:** ![extempore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6bbea6/32.png) [@extempore](https://www.ruby-forum.com/u/extempore)\
**Post date:** [January 6, 2008, 5:11pm UTC](https://www.ruby-forum.com/t/a-sort-question/125125/4 "2008-01-06T17:11:46Z")

</div>

since I’m new to Ruby  
I try to explore my horizons and would like to know how it’s done with  
an if structure or with bubble sort  
thanks again for providing an example  
Paul

Paul P. wrote:

> not that it’s slow but I would like to achieve the same with the if  
> structure and was wondering how this can be done if someone could help  
> me with an example it would be much appreciated
> 
> Daniel W. wrote:
> 
> > Paul P. wrote:
> > 
> > > I know you could solve it like the example below however I would like to  
> > > do it with an IF structure or with a bubble sort but not able to figure  
> > > this out
> > 
> > Why? Is it slow? Does it not do exactly what you want?

---

<div class="post-metadata">

**Author:** ![extempore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6bbea6/32.png) [@extempore](https://www.ruby-forum.com/u/extempore)\
**Post date:** [January 7, 2008, 6:40am UTC](https://www.ruby-forum.com/t/a-sort-question/125125/5 "2008-01-07T06:40:52Z")

</div>

Isn’t there anybody who would like to help me out here with an example?

Paul P. wrote:

> since I’m new to Ruby  
> I try to explore my horizons and would like to know how it’s done with  
> an if structure or with bubble sort  
> thanks again for providing an example  
> Paul
> 
> Paul P. wrote:
> 
> > not that it’s slow but I would like to achieve the same with the if  
> > structure and was wondering how this can be done if someone could help  
> > me with an example it would be much appreciated
> > 
> > Daniel W. wrote:
> > 
> > > Paul P. wrote:
> > > 
> > > > I know you could solve it like the example below however I would like to  
> > > > do it with an IF structure or with a bubble sort but not able to figure  
> > > > this out
> > > 
> > > Why? Is it slow? Does it not do exactly what you want?
