I have an array of hash :
tags_on
=> [{:point=>[“a”, “b”, “c”]}, {:comma=>[“d”, “e”]}]
and I would like to get the value [“d”, “e”] for a specified
key :comma
is there any DRY way to do it or should I loop into the array ?
Assuming the keys are unique why don’t you build it as a straight hash
in the first place? If they are not unique then you are in trouble
anyway. If you are stuck with the array then I think I would use
collect to convert it into a straight hash first.
I’ve had to build little arrays of single-key hashes like this to work
around 1.8.6 not having ordered hash semantics.
…or you have a normal hash with one of the values as an array of the
keys in the order you want (I normally call it “:order”). Then when
you want to iterate you hash in order: