Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/kafkat/command/reassign.rb

Instance Method Summary collapse

Instance Method Details

#hmap(&block) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/kafkat/command/reassign.rb', line 12

def hmap(&block)
  h = Hash.new
  self.keys.each do |key|
    hash = block.call(key, self[key])

    h[hash.keys.first] = hash[hash.keys.first]
  end
  h
end

#hmap!(&block) ⇒ Object



2
3
4
5
6
7
8
9
10
# File 'lib/kafkat/command/reassign.rb', line 2

def hmap!(&block)
  self.keys.each do |key|
    hash = block.call(key, self[key])

    self[hash.keys.first] = hash[hash.keys.first]
    self.delete(key)
  end
  self
end