Sha256: a393f054876d4ae72620bc3472ef0fb447d17994bcbe13ebd5e92fa8a0710df0
Contents?: true
Size: 679 Bytes
Versions: 2
Compression:
Stored size: 679 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 # CREDIT: 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
facets-2.2.1 | lib/core/facets/hash/autonew.rb |
facets-2.3.0 | lib/core/facets/hash/autonew.rb |