Sha256: 9913408760a52674d8aa3ffdacc6a1d1bdd1069fc122afed7965a29f5fa15fa1

Contents?: true

Size: 343 Bytes

Versions: 1

Compression:

Stored size: 343 Bytes

Contents

# frozen_string_literal: true

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
darthjee-core_ext-1.6.2 lib/darthjee/core_ext/hash/transposeable.rb