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.



145
146
147
# File 'lib/whimsy/asf/ldap.rb', line 145

def initialize(&initializer)
  @initializer = initializer
end

Instance Method Details

#[](key) ⇒ Object



155
156
157
158
159
160
161
162
163
# File 'lib/whimsy/asf/ldap.rb', line 155

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



149
150
151
152
153
# File 'lib/whimsy/asf/ldap.rb', line 149

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