Hi,
I'd also be interested in renaming one or more hash keys. My use case:
ActiveWarehouse-ETL (
http://activewarehouse.rubyforge.org/) is an ETL
tool handling rows of data as Hash, and it's very common to have to
rename a field in that case. So far here's what I do:
# rename a bunch of fields
def rename_fields!(row,fields_to_rename,fields_new_nam es)
throw "Array size mismatch" unless fields_new_names.size ==
fields_to_rename.size
mapping = Hash[*fields_to_rename.zip(fields_new_names).flatten]
mapping.each { |old_name,new_name| row[new_name] = row[old_name];
row.delete(old_name) }
end
Does anyone know a built-in way of achieving something similar ?
best
Thibaut