
Issue #21182 has been reported by calebm (Caleb Meyer). ---------------------------------------- Feature #21182: Add Hash#rename https://bugs.ruby-lang.org/issues/21182 * Author: calebm (Caleb Meyer) * Status: Open ---------------------------------------- Abstract: Implement Hash#rename which takes as arguments a from key and a to key and renames the from key to the new name. Background: One of the most common data transformations for a hash (in my experience) is renaming a single key. You can do this with the existing hash methods (e.g. `hash['new'] = hash.delete('old')` or `hash.transform_keys('old' => 'new')`) but they feel a bit clunky. Proposal: Add a new method to Hash, something like this: ```ruby class Hash # usage { old: 'value' }.rename(:old, to: :new) # => { new: 'value' } def rename(from, to:) transform_keys(from => to) end def rename!(from, to:) transform_keys!(from => to) end end ``` -- https://bugs.ruby-lang.org/