J
Joshua Muheim
Hi all
The title of this topic is not very good, but I didn't really know how
to describe it in just a few words...
So here is what I need to do:
I have a array of some objects:
[obj1, obj2, obj3, obj4]
All objects have a method "status" that returns a status object, like
"open", "request", "cancelled", "completed" etc.
Now I'd like to sort the elements after theses statuses into a new hash,
so in the end it should look something like this:
{status1 => [obj1, obj3],
status3 => [obj2],
status4 => [obj4]}
I need this because I want then to iterate through the hash and display
an HTML list grouped by status:
<ul>
<li>
Request:
<ul>
<li>Object 1</li>
<li>Object 3</li>
</ul>
</li>
<li>
Cancelled:
<ul>
<li>Object 2</li>
</ul>
</li>
... and so on...
</ul>
What's an elegant way to do this?
Thanks a lot,
Josh
The title of this topic is not very good, but I didn't really know how
to describe it in just a few words...
So here is what I need to do:
I have a array of some objects:
[obj1, obj2, obj3, obj4]
All objects have a method "status" that returns a status object, like
"open", "request", "cancelled", "completed" etc.
Now I'd like to sort the elements after theses statuses into a new hash,
so in the end it should look something like this:
{status1 => [obj1, obj3],
status3 => [obj2],
status4 => [obj4]}
I need this because I want then to iterate through the hash and display
an HTML list grouped by status:
<ul>
<li>
Request:
<ul>
<li>Object 1</li>
<li>Object 3</li>
</ul>
</li>
<li>
Cancelled:
<ul>
<li>Object 2</li>
</ul>
</li>
... and so on...
</ul>
What's an elegant way to do this?
Thanks a lot,
Josh