Class: LazyMethods::LazyProxy

Inherits:
Proxy
  • Object
show all
Defined in:
lib/lazy_methods.rb

Overview

:nodoc:

Constant Summary

Constants inherited from Proxy

Proxy::PROTECTED_METHODS

Instance Method Summary collapse

Methods inherited from Proxy

#method_missing

Constructor Details

#initialize(&block) ⇒ LazyProxy

Returns a new instance of LazyProxy.



96
97
98
# File 'lib/lazy_methods.rb', line 96

def initialize(&block)
  @method_call = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class LazyMethods::Proxy

Instance Method Details

#__proxy_loaded__Object

Helper method that indicates if the proxy has loaded the original method results yet.



107
108
109
# File 'lib/lazy_methods.rb', line 107

def __proxy_loaded__
  !!defined?(@proxy_result)
end

#__proxy_result__Object

Get the result of the original method call. The original method must only be called once.



101
102
103
104
# File 'lib/lazy_methods.rb', line 101

def __proxy_result__
  @proxy_result = @method_call.call unless defined?(@proxy_result)
  @proxy_result
end