Method: Immutable::Hash#invert
- Defined in:
- lib/immutable/_core.rb
#invert ⇒ Hash
Return a new Hash created by using keys as values and values as keys. If there are multiple values which are equivalent (as determined by #hash and #eql?), only one out of each group of equivalent values will be retained. Which one specifically is undefined.
659 660 661 662 663 |
# File 'lib/immutable/_core.rb', line 659 def invert pairs = [] each { |k,v| pairs << [v, k] } self.class.new(pairs, &@default) end |