Method: Icasework::LazyHash#initialize
- Defined in:
- lib/icasework/lazy_hash.rb
#initialize(hash, key = nil, &block) ⇒ LazyHash
Returns a new instance of LazyHash.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/icasework/lazy_hash.rb', line 11 def initialize(hash, key = nil, &block) @hash = hash @key = key @block = block @hash.default_proc = proc do |h, k| new_hash = @block.call new_hash = new_hash[@key] if @key h[k] = new_hash.fetch(k) end super(@hash) end |