In some scenarios of Ruby 1.8, if I have hash
# k, v Order fu = {"gym" => 1, "bar" = & gt; 1, "Joe" = & gt; 2} sorted_by_values = foo.sort {| A, b A [1] & lt; ==> B [1]} #sorted_by_values is an array of arrays, it is no longer a hash! My action is to create the rule to_hash
for the Array class. square array DEF
to_hash (& block) hash [* self.collect {| K, v | [K, v]}. Flaton] End End
I can then do the following:
sorted_by_values.to_hash.keys.join ','
Is there a better way to do this?
There is no such thing as anarchold sorted hash by the hashas definition, your best The condition is probably possible to collect keys from the collected array and then add one to the result
sortedByValues = foo.sort {| A, b A [1] & lt; ==> B [1]} Sorted Belgian Colllect {| A. A [0]}. Insert ','
Comments
Post a Comment