Sha256: 024a7be21de063a1d0fc87616c987d96e420ca4d6e49b42ddcf698b36aacd438

Contents?: true

Size: 682 Bytes

Versions: 10

Compression:

Stored size: 682 Bytes

Contents

#--
# Credit goes to Jan Molic and Ara.T.Howard
#++

class Hash

  #  Hash which auto initializes it's children.
  #
  #   ah = Hash.auto
  #   ah['section one']['param one'] = 4
  #   ah['section one']['param two'] = 5
  #   ah['section one']['param three'] = 2
  #   ah['section one']['param four'] = 3
  #
  #   p ah
  #   # {"section one"=>{"param one"=>4, "param four"=>3, "param three"=>2, "param two"=>5}}
  #
  #   p ah['section one'].keys
  #   # ["param one", "param four", "param three", "param two"]
  #

  def self.auto(*args)
    #new(*args){|a,k| a[k] = self.class::new(*args)}
    leet = lambda { |hsh, key| hsh[key] = new( &leet ) }
    new(*args,&leet)
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
facets-1.7.0 lib/facets/core/hash/self/auto.rb
facets-1.7.30 lib/facets/core/hash/self/auto.rb
facets-1.7.38 lib/facets/core/hash/self/auto.rb
facets-1.7.46 lib/facets/core/hash/self/auto.rb
facets-1.8.0 lib/facets/core/hash/self/auto.rb
facets-1.8.20 lib/facets/core/hash/self/auto.rb
facets-1.8.49 lib/facets/core/hash/self/auto.rb
facets-1.8.51 lib/facets/core/hash/self/auto.rb
facets-1.8.54 lib/facets/core/hash/self/auto.rb
facets-1.8.8 lib/facets/core/hash/self/auto.rb