I want to normalise a Hash
's keys using a normalisation function so that this hash
{"aType" => 1, "b_Type" => 2}
would be converted to
{:atype => 1, :btype => 2}
Here, the normalisation function removes underscores from the keys, downcases them, and makes them symbols.
I wrote the following using map
(assume normalize
is a normalisation method):
params = params.map {|k,v| {normalize(k) => v}}.inject(:merge)
Is there any better way to do this?
This question is related to a question "How to replace all hash keys having a '.'?". I want to know the optimal (less verbose or faster) way to do this.