Module: Darthjee::CoreExt::Hash::Transposeable

Included in:
Darthjee::CoreExt::Hash
Defined in:
lib/darthjee/core_ext/hash/transposeable.rb

Instance Method Summary collapse

Instance Method Details

#transposeObject



16
17
18
19
20
21
22
# File 'lib/darthjee/core_ext/hash/transposeable.rb', line 16

def transpose
  {}.tap do |new_hash|
    each do |k, v|
      new_hash[v] = k
    end
  end
end

#transpose!Object



7
8
9
10
11
12
13
14
# File 'lib/darthjee/core_ext/hash/transposeable.rb', line 7

def transpose!
  aux = dup
  keys.each { |k| delete(k) }
  aux.each do |k, v|
    self[v] = k
  end
  self
end