On 11/03/14 12:58 PM, Matthaus Owens wrote: > I don't know about the specific implementation of join_keys_to_values, > but ruby's hash behavior changed between the 1.8 series and 1.9 and > later[1]. In ruby 1.8 hashes are enumerated in a seemingly unsorted > manner, while in ruby 1.9 and later hashes are enumerated in insertion > order. If you are on ruby 1.8, it would be worth seeing if you > experience the same issues in ruby 1.9 or later. > > [1] - > http://stackoverflow.com/questions/7065915/why-is-my-hash-autosorting-itself
oh, well that's interesting. thanks for the feedback, I'll se about using ruby 1.9.x > On Tue, Mar 11, 2014 at 9:27 AM, Gabriel Filion <lelu...@gmail.com> wrote: >> Hi there, >> >> Say I have a hash like {a=>'1',b=>'2'} and I'd like to get a string that >> looks like "a=1,b=2". I tried using a combination of >> join_keys_to_values() and join() and the result looked correct, but was >> unstable. That unstability is because hashes are not always "sorted" the >> same way. >> >> An unstable string means that the config file in which I use it gets >> modified for no reason from time to time and this triggers an >> unnecessary service refresh. >> >> I'm currently using an inline template to achieve what I want, since >> with ruby I can use h.sort.map to always get results in the same order >> from a hash "h". >> >> Thing is, stdlib's sort() function only accepts strings or arrays. >> >> >> Is there a way to get a "stable" string with current means? >> >> Otherwise, would it be an acceptable idea to add support for hashes in >> sort() ? -- Gabriel Filion
signature.asc
Description: OpenPGP digital signature