# Changing order of hash

**URL:** <https://www.ruby-forum.com/t/changing-order-of-hash/157101>\
**Category:** Rails\
**Created:** [January 7, 2009, 12:08pm UTC](https://www.ruby-forum.com/t/changing-order-of-hash/157101 "2009-01-07T12:08:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a698b9/32.png) [@vanight](https://www.ruby-forum.com/u/vanight)\
**Post date:** [January 7, 2009, 12:08pm UTC](https://www.ruby-forum.com/t/changing-order-of-hash/157101/1 "2009-01-07T12:08:42Z")

</div>

I’ve got a constant of difficulty levels in my ‘Tutorial’ model which is  
a hash of

DIFFICULTIES = {“Beginner” =\> 1, “Intermediate” =\> 2, “Advanced” =\> 3}

However when I pass it to my options\_for\_select helper they appear in a  
completely different order. Is there any way to keep them in the correct  
order?

Also is this the best way to keep a small list like this that isn’t  
related to a database table?

---

<div class="post-metadata">

**Author:** ![vanight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a698b9/32.png) [@vanight](https://www.ruby-forum.com/u/vanight)\
**Post date:** [January 7, 2009, 12:49pm UTC](https://www.ruby-forum.com/t/changing-order-of-hash/157101/2 "2009-01-07T12:49:05Z")

</div>

On 7 Jan 2009, at 11:08, David Nicholson wrote:

> correct  
> order?

Hashes are unordered (at least in ruby 1.8). As far as  
options\_for\_select is concerned you can use something like  
[[‘Beginner’, 1], …]

> Also is this the best way to keep a small list like this that isn’t  
> related to a database table?

constant in the tutorial model sounds fine to me.

Fred

---

<div class="post-metadata">

**Author:** ![vanight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a698b9/32.png) [@vanight](https://www.ruby-forum.com/u/vanight)\
**Post date:** [January 7, 2009, 1:15pm UTC](https://www.ruby-forum.com/t/changing-order-of-hash/157101/3 "2009-01-07T13:15:08Z")

</div>

Can’t you use .sort Method or switch to Ruby 1.9?  
Here a tip from Ezra Z.  
[http://www.ruby-forum.com/topic/50146#16582](http://www.ruby-forum.com/topic/50146#16582)

Chris

---

<div class="post-metadata">

**Author:** ![vanight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a698b9/32.png) [@vanight](https://www.ruby-forum.com/u/vanight)\
**Post date:** [January 7, 2009, 4:56pm UTC](https://www.ruby-forum.com/t/changing-order-of-hash/157101/4 "2009-01-07T16:56:51Z")

</div>

Thanks a lot

The array method did the trick.
