My table field names are lowercase and the field names I get from CSV files are camelcase. Is there anyway I can convert the keys of an array of hashes to lowercase?
Since this was tagged with Rails.
With ActiveSupport starting vom version 3.0 you can use a HashWithIndifferentAccess.
That will allow lower/uppercase/symbol writing to access the keys or your Hash.
my_hash = { "camelCase": "some value" }
my_hash.with_indifferent_access[:camelcase] # 'some value'
my_hash.with_indifferent_access['camelcase'] # 'some value'
my_hash.with_indifferent_access['camelCase'] # 'some value'
my_hash.with_indifferent_access['CAMELCASE'] # 'some value'
ActiveSupport 4.0.2 also introduced this:
my_hash.deep_transform_keys!(&:downcase)
# or if your hash isn't nested:
my_hash.transform_keys!(&:downcase)