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.



255
256
257
# File 'lib/whimsy/asf/ldap.rb', line 255

def initialize(&initializer)
  @initializer = initializer
end

Instance Method Details

#[](key) ⇒ Object



265
266
267
268
269
270
271
272
273
# File 'lib/whimsy/asf/ldap.rb', line 265

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



259
260
261
262
263
# File 'lib/whimsy/asf/ldap.rb', line 259

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