Module: Plumbum::Providers::Lazy

Defined in:
lib/plumbum/providers/lazy.rb

Overview

Provider that calls proc values and returns the result.

Add Plumbum::Providers::Lazy for values that have a consistent definition but changing value, such as class definitions under code reloading.

Instance Method Summary collapse

Instance Method Details

#get(key) ⇒ Object?

Retrieves the provided value for the given key.

If the value is a Proc, the Proc is called and the value returned by the Proc is returned by #get. Otherwise, #get returns the value directly.

Parameters:

  • key (String, Symbol)

    the key for the requested value.

Returns:

  • (Object, nil)

    the requested object, or nil if the provider does not have a value for the requested key.



20
21
22
23
24
# File 'lib/plumbum/providers/lazy.rb', line 20

def get(key)
  value = super

  value.is_a?(Proc) ? value.call : value
end