Class: HashFilter::Operation::Rename
- Inherits:
-
HashFilter::Operation
- Object
- HashFilter::Operation
- HashFilter::Operation::Rename
- Defined in:
- lib/hash_filter/operation/rename.rb
Overview
Rename a key in a hash
Instance Method Summary collapse
- #execute(hash, old) ⇒ Object
-
#initialize(from, to) ⇒ Rename
constructor
A new instance of Rename.
Methods inherited from HashFilter::Operation
Constructor Details
#initialize(from, to) ⇒ Rename
5 6 7 8 |
# File 'lib/hash_filter/operation/rename.rb', line 5 def initialize(from, to) super(from) @to = to end |
Instance Method Details
#execute(hash, old) ⇒ Object
10 11 12 13 |
# File 'lib/hash_filter/operation/rename.rb', line 10 def execute(hash, old) new = old.gsub(@key, @to) hash[new] = hash.delete(old) end |