Sha256: 9dd82b777a6ea3994ee29fd3dc8c4388e7685f1a1f5938ab630edfc3cfb0933f

Contents?: true

Size: 605 Bytes

Versions: 1

Compression:

Stored size: 605 Bytes

Contents

# frozen_string_literal: true

module Darthjee
  module CoreExt
    module Array
      class HashBuilder
        attr_accessor :values, :keys

        def initialize(values, keys)
          @values = values.dup
          @keys = keys.dup
        end

        def build
          fixes_sizes

          ::Hash[[keys, values].transpose]
        end

        private

        def fixes_sizes
          return unless needs_resizing?
          values.concat ::Array.new(keys.size - values.size)
        end

        def needs_resizing?
          keys.size > values.size
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
darthjee-core_ext-1.7.0 lib/darthjee/core_ext/array/hash_builder.rb