Module: LazyHash

Defined in:
lib/lazyhash.rb

Class Method Summary collapse

Class Method Details

.add(hash, key, value) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/lazyhash.rb', line 3

def add(hash, key, value)
  skeys = key.split(".")
  f = skeys.shift
  if skeys.empty?
    hash.send("[]=", f, value) unless !hash.is_a?(Hash) || (hash.has_key?(f) && hash[f].is_a?(Hash))
  else
    add(hash[f], skeys.join("."), value)
  end
end

.build_hashObject



13
14
15
16
# File 'lib/lazyhash.rb', line 13

def build_hash
  lazy = lambda { |h,k| h[k] = Hash.new(&lazy) }
  Hash.new(&lazy)
end

.no_lazy(hash) ⇒ Object



18
19
20
# File 'lib/lazyhash.rb', line 18

def no_lazy(hash)
  eval(hash.inspect)
end