Class: ASF::LazyHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/whimsy/asf/ldap.rb

Instance Method Summary collapse

Constructor Details

#initialize(&initializer) ⇒ LazyHash

Returns a new instance of LazyHash.



396
397
398
# File 'lib/whimsy/asf/ldap.rb', line 396

def initialize(&initializer)
  @initializer = initializer
end

Instance Method Details

#[](key) ⇒ Object



406
407
408
409
410
411
412
413
414
# File 'lib/whimsy/asf/ldap.rb', line 406

def [](key)
  result = super
  if not result and not keys.include? key and @initializer
    merge! @initializer.call || {}
    @initializer = nil
    result = super
  end
  result
end

#loadObject



400
401
402
403
404
# File 'lib/whimsy/asf/ldap.rb', line 400

def load
 return unless @initializer
 merge! @initializer.call || {}
 @initializer = super
end