Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/hash/inverse.rb

Overview

inverse from Tilo Sloboda (now in facets)

Instance Method Summary collapse

Instance Method Details

#inverseObject



6
7
8
9
10
11
12
# File 'lib/hash/inverse.rb', line 6

def inverse
  i = Hash.new
  self.each_pair do |k,v|
    if (Array === v) ; v.each{ |x| i[x] = ( i.has_key?(x) ? [k,i[x]].flatten : k ) }
    else ; i[v] = ( i.has_key?(v) ? [k,i[v]].flatten : k ) end
  end ; i  
end