From: Hal Fulton Date: 2006-08-13T17:02:00+09:00 Subject: Re: A use case for an ordered hash Francis Cianfrocca wrote: > On 8/13/06, Hal Fulton wrote: > >> actions = { /abcd/ => lambda { do_this }, >> /xyz/ => lambda { do_that }, >> /abc/ => lambda { other }} >> > > > actions.keys.sort {|a,b| b.to_s <=> a.to_s}.each {|k| > if k =~ your_string > actions[k].call > break > end > } > > A more-greedy regex sorts lexicographically behind a head-matching > less-greedy one. > Clever workaround. Thanks for that. There are all kinds of workarounds for situations like these. I don't *need* an ordered hash. I don't even *need* a case statement, as I could do the same thing with a bunch of ifs. And so on. Hal