On 8/14/06, Bil Kleb <Bil.Kleb / nasa.gov> wrote:
> Here's my latest one[1]:
>
> I had a string with a bunch of tagged "tolerance fields",
> e.g., >>1+/-10% 'tag'<< (a mini DSL?).  Based on some sort
> of distribution function, e.g., uniform or Gaussian,
> I generated an array of samples for each tagged field.
> A regular hash was a perfect fit,
>
>    samples[tag] = [ sample1, sample2, .. ]
>
> *until* another requirement came up: to present the tags
> in order of appearance.


I've had to deal with this (interestingly, in something that was
*intended* as a DSL). Just add another field to the structure you
store in the hash and have it increment a global sequence number when
you create it. A little clunky but later you can say:

hash.values.sort {|a,b| a.seq <=> b.seq}.each {|v|
  # whatever
}