<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Taking a cue from @JEG2, you could reverse it:</div><div><br></div><div>catalogue.select {...}.map(&:reverse).sort.map(&:reverse)</div><div><br></div><div>...but (as already mentioned) #sort_by is much easier to read:</div><div><br></div><div>catalogue.select {...}.sort_by(&:last)</div><div><br><div>--</div>(Sent from phone. Please excuse: brevity, top posting, hilarious autocorrections.)</div><div><br>On Jun 17, 2014, at 3:46 AM, Stephen Nelson-Smith <<a href="mailto:sanelson@gmail.com">sanelson@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">I have a hash that looks like this:<div><br></div><div><div>{"ami-c3c73c7f"=>"tn-example 1980-09-12T17:53:25Z",</div><div> "ami-600925fe"=>"sns-example 1983-01-05T16:21:08Z",</div>
<div> "ami-131f1007"=>"dk-example 2005-01-27T23:03:01Z",</div><div> "ami-98d4ddef"=>"tn-example 2002-10-27T11:52:26Z",</div><div> "ami-fe6af742"=>"sns-example 1998-11-22T09:54:51Z",</div>
<div> "ami-09966e45"=>"dk-example 1993-01-09T13:23:45Z",</div><div> "ami-44e6ee6a"=>"tn-example 2013-12-23T20:52:28Z",</div><div> "ami-cbf7f1a9"=>"sns-example 1979-09-09T07:15:47Z",</div>
<div> "ami-fcd2e7ac"=>"dk-example 2007-09-02T18:34:05Z"}</div><div><br></div><div>I want to filter this hash by value and return them in sorted date order.  The implementation I have just seems ugly:</div>
<div><br></div><div><div>catalogue.select {|id, name| name.match /sns-example/ }.sort { |id, name| name[1] <=> id[1] }</div><div>=> [["ami-a65e21cc", "sns-example 2011-10-03T11:15:49Z"],</div>
<div> ["ami-9a401c41", "sns-example 1983-09-22T15:26:00Z"],</div><div> ["ami-9f9ae4d8", "sns-example 1971-03-06T03:58:52Z"]]</div></div><div><br></div><div><br></div><div>I don't like the way sort takes my hash and makes it into an array of tuples... and I'd really like it to return an array of single key/value hashes... </div>
<div><br></div><div>Also, is there a more elegant way to perform the filter/search?</div><div><br></div><div>S.</div><div><br></div>-- <br>Stephen Nelson-Smith<br>Technical Director<br>Atalanta Systems Ltd<br><a href="http://www.atalanta-systems.com">www.atalanta-systems.com</a>
</div></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Chat mailing list</span><br><span><a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a></span><br><span><a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a></span><br></div></blockquote></body></html>