Sha256: a1a78b2f925215a536df435343304beeebb0835b60695102e81a4861566e4b20

Contents?: true

Size: 665 Bytes

Versions: 10

Compression:

Stored size: 665 Bytes

Contents

class Hash

  #  Hash which auto initializes it's children.
  #
  #   ah = Hash.autonew
  #   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"]
  #
  # CREDIT: Trans, Jan Molic

  def self.autonew(*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-2.8.4 lib/core/facets/hash/autonew.rb
facets-2.8.3 lib/core/facets/hash/autonew.rb
facets-2.8.2 lib/core/facets/hash/autonew.rb
facets-2.8.1 lib/core/facets/hash/autonew.rb
facets-2.8.0 lib/core/facets/hash/autonew.rb
facets-2.7.0 lib/core/facets/hash/autonew.rb
facets-2.6.0 lib/core/facets/hash/autonew.rb
facets-2.5.1 lib/core/facets/hash/autonew.rb
facets-2.5.0 lib/core/facets/hash/autonew.rb
facets-2.5.2 lib/core/facets/hash/autonew.rb