Class: HashFilter::Operation::Rename

Inherits:
HashFilter::Operation show all
Defined in:
lib/hash_filter/operation/rename.rb

Overview

Rename a key in a hash

Instance Method Summary collapse

Methods inherited from HashFilter::Operation

#matches?

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