Sha256: be8be71c7a8fd550fdadcd996e13200e9e5e3d7984ab4f1ae6e6822d5920560c

Contents?: true

Size: 367 Bytes

Versions: 41

Compression:

Stored size: 367 Bytes

Contents

module Doing
  ##
  ## Array helpers
  ##
  module ArrayNestedHash
    ##
    ## Convert array to nested hash, setting last key to value
    ##
    ## @param      value  The value to set
    ##
    def nested_hash(value = nil)
      hsh = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }
      hsh.dig(*self[0..-2])[fetch(-1)] = value
      hsh
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
doing-2.1.88 lib/doing/array/nested_hash.rb
doing-2.1.87 lib/doing/array/nested_hash.rb
doing-2.1.86 lib/doing/array/nested_hash.rb
doing-2.1.85 lib/doing/array/nested_hash.rb
doing-2.1.84 lib/doing/array/nested_hash.rb
doing-2.1.83 lib/doing/array/nested_hash.rb
doing-2.1.82 lib/doing/array/nested_hash.rb
doing-2.1.81 lib/doing/array/nested_hash.rb
doing-2.1.80 lib/doing/array/nested_hash.rb
doing-2.1.79 lib/doing/array/nested_hash.rb
doing-2.1.78 lib/doing/array/nested_hash.rb
doing-2.1.77 lib/doing/array/nested_hash.rb
doing-2.1.76 lib/doing/array/nested_hash.rb
doing-2.1.75 lib/doing/array/nested_hash.rb
doing-2.1.74 lib/doing/array/nested_hash.rb
doing-2.1.73 lib/doing/array/nested_hash.rb
doing-2.1.72 lib/doing/array/nested_hash.rb
doing-2.1.69 lib/doing/array/nested_hash.rb
doing-2.1.68 lib/doing/array/nested_hash.rb
doing-2.1.66 lib/doing/array/nested_hash.rb