Class: Manana
- Inherits:
-
Object
- Object
- Manana
- Defined in:
- lib/manana.rb,
lib/manana/version.rb
Overview
Manana lets you defer the initialization of an object until its methods are called.
Constant Summary collapse
- VERSION =
"1.0.0"
Class Method Summary collapse
-
.wrap(&initialization_block) ⇒ Deferrable
wraps the initialization of an object so that it can be deferred to a later time when object methods are called.
Instance Method Summary collapse
-
#_object ⇒ Object
allows direct access to the wrapped object -- useful for debugging.
-
#method_missing(method, *args, &block) ⇒ Object
passes any method call through to the wrapped object after ensuring that the initialization block has successfully completed once (thereby initializing the wrapped object).
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Once the initialization block succeeds, it keeps the resulting object for subsequent method calls.
passes any method call through to the wrapped object after ensuring that the initialization block has successfully completed once (thereby initializing the wrapped object).
40 41 42 |
# File 'lib/manana.rb', line 40 def method_missing(method, *args, &block) _object.send(method, *args, &block); end |
Class Method Details
.wrap(&initialization_block) ⇒ Deferrable
wraps the initialization of an object so that it can be deferred to a later time when object methods are called.
29 30 31 |
# File 'lib/manana.rb', line 29 def self.wrap(&initialization_block) new(&initialization_block) end |
Instance Method Details
#_object ⇒ Object
allows direct access to the wrapped object -- useful for debugging
46 47 48 49 50 |
# File 'lib/manana.rb', line 46 def _object @mutex.synchronize do @object ||= @deferred_initialization.call end end |