Sha256: e81161259ffafe2317a165534dad84570b42ed616f5995dcc8f44480a4b7eff2

Contents?: true

Size: 523 Bytes

Versions: 13

Compression:

Stored size: 523 Bytes

Contents

# from https://gist.github.com/745617

module LazyHash
  class << self
    def lazy_add(hash, key, value, pre = nil)
      skeys = key.split(".")
      f = skeys.shift
      if skeys.empty?
        pre.nil? ? hash.send("[]=", f, value) : pre.send("[]=", f, value)
      else
        pre = pre.nil? ? hash.send("[]", f) : pre.send("[]", f)
        lazy_add(hash, skeys.join("."), value, pre)
      end
    end

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
interpret-1.1.2 test_app/lib/lazy_hash.rb
interpret-1.1.1 test_app/lib/lazy_hash.rb
interpret-1.1.0 test_app/lib/lazy_hash.rb
interpret-1.0.2 test_app/lib/lazy_hash.rb
interpret-1.0.1 test_app/lib/lazy_hash.rb
interpret-0.2.1 test_app/lib/lazy_hash.rb
interpret-1.0.0 test_app/lib/lazy_hash.rb
interpret-0.2.0 test_app/lib/lazy_hash.rb
interpret-0.1.5 test_app/lib/lazy_hash.rb
interpret-0.1.4 test_app/lib/lazy_hash.rb
interpret-0.1.3 test_app/lib/lazy_hash.rb
interpret-0.1.2 test_app/lib/lazy_hash.rb
interpret-0.1.1 test_app/lib/lazy_hash.rb