From: "ara.t.howard" Date: 2007-11-15T01:59:34+09:00 Subject: Re: Ordered Hash Usefulness On Nov 13, 2007, at 1:53 PM, Devi Web Development wrote: > What I really want to know is, is there some usefulness to ordered > pairs I am missing? i use mine (gem install alib, alib.orderedhash.new) all the time for generating reports in yaml. report = alib.orderedautohash.new report['name']['first'] = 'ara' report['name']['last'] = 'howard' and this make the report print the same using y report all the time. if you use a hash the report will have varying order both within and between runs. ruby queue uses this for job output, which looks like this: - jid: 4669 priority: 42 state: finished submitted: 2007-11-14 09:07:36.124312 started: 2007-11-14 09:08:26.226328 finished: 2007-11-14 09:09:19.405155 elapsed: 53.178827 submitter: mussel.ngdc.noaa.gov runner: clam.ngdc.noaa.gov stdin: stdin/4669 stdout: stdout/4669 stderr: stderr/4669 pid: 16804 exit_status: 0 tag: eds restartable: true command: sif eds process_incoming /dmsp/nrt/subscriptions/eds/ incoming/F15200711141422.d.OIS - jid: 4670 priority: 42 state: finished submitted: 2007-11-14 09:07:36.413314 started: 2007-11-14 09:08:26.342514 finished: 2007-11-14 09:11:44.703900 elapsed: 198.361386 submitter: mussel.ngdc.noaa.gov runner: clam.ngdc.noaa.gov stdin: stdin/4670 stdout: stdout/4670 stderr: stderr/4670 pid: 16860 exit_status: 0 tag: flo restartable: true command: sif flo process_incoming /dmsp/nrt/subscriptions/flo/ incoming/F15200711141422.d.OIS it's *really* disorienting for users when jobs come out in different orders job to job, and the next run dumps out something different yet again. make using 'diff' extremely frustrating. the other use case is for something like a database tuple or a set of columns (mapped by name) displayed on an interface: you want to use them by name, for instance interface.columns['ssn'] but also want to say interface.columns.each{|k,c| render c} and have that come out in order. arrayfields (gem install arrayfields) skins this cat from the other direction: allowing normal arrays to support keyword acccess. regards. a @ http://codeforpeople.com/ -- it is not enough to be compassionate. you must act. h.h. the 14th dalai lama