[LRUG] Sorting a hash by value

Lorenzo Barasti lorenzo.barasti at gmail.com
Tue Jun 17 06:02:30 PDT 2014


Hi Stephen,

I agree with Tom and Paul about your data structure not being ideal.

Anyway, I'd suggest you use #sort_by

catalogue.select{|_,v| v[/sns-example/]}.sort_by{|_,v| v}

​

Cheers,

Lorenzo


On Tue, Jun 17, 2014 at 12:36 PM, Paul Robinson <paul at iconoplex.co.uk>
wrote:

> On 17 June 2014 12:14, Tom Stuart <tom at codon.com> wrote:
>
> Server = Struct.new(:ami, :name, :time)
>
>
> Everybody seems to forget about Struct:
> http://www.ruby-doc.org/core-2.1.2/Struct.html
>
> On many occasions I've seen classes that have attributes but no methods -
> they should clearly be Structs.
>
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20140617/13ab9291/attachment-0003.html>


More information about the Chat mailing list