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.



98
99
100
# File 'lib/whimsy/asf/ldap.rb', line 98

def initialize(&initializer)
  @initializer = initializer
end

Instance Method Details

#[](key) ⇒ Object



108
109
110
111
112
113
114
115
116
# File 'lib/whimsy/asf/ldap.rb', line 108

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

#load ⇒ Object



102
103
104
105
106
# File 'lib/whimsy/asf/ldap.rb', line 102

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