Class: LazyObject
- Inherits:
- BasicObject
- Defined in:
- app/models/lazy_object.rb
Instance Method Summary collapse
-
#__target_object__ ⇒ Object
Cached target object.
-
#initialize(&callable) ⇒ LazyObject
constructor
A new instance of LazyObject.
-
#method_missing(method_name, *args, &block) ⇒ Object
Forwards all method calls to the target object.
Constructor Details
#initialize(&callable) ⇒ LazyObject
Returns a new instance of LazyObject.
2 3 4 |
# File 'app/models/lazy_object.rb', line 2 def initialize(&callable) @__callable__ = callable end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
Forwards all method calls to the target object.
12 13 14 |
# File 'app/models/lazy_object.rb', line 12 def method_missing(method_name, *args, &block) __target_object__.send(method_name, *args, &block) end |
Instance Method Details
#__target_object__ ⇒ Object
Cached target object.
7 8 9 |
# File 'app/models/lazy_object.rb', line 7 def __target_object__ @__target_object__ ||= @__callable__.call end |