Sha256: 56fafb28c25c9405089ec799ea6f8eecacf900f8f89caad2e9fccc8f75b09312

Contents?: true

Size: 463 Bytes

Versions: 5

Compression:

Stored size: 463 Bytes

Contents

# frozen_string_literal: true

module Darthjee
  module CoreExt
    module 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
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
darthjee-core_ext-1.7.4 lib/darthjee/core_ext/hash/transposeable.rb
darthjee-core_ext-1.7.3 lib/darthjee/core_ext/hash/transposeable.rb
darthjee-core_ext-1.7.2 lib/darthjee/core_ext/hash/transposeable.rb
darthjee-core_ext-1.7.1 lib/darthjee/core_ext/hash/transposeable.rb
darthjee-core_ext-1.7.0 lib/darthjee/core_ext/hash/transposeable.rb