Class: EDango::DI::Proxy
Defined Under Namespace
Classes: ProxyError
Instance Attribute Summary collapse
-
#delegate ⇒ Object
readonly
Returns the value of attribute delegate.
-
#interfaces ⇒ Object
readonly
Returns the value of attribute interfaces.
Instance Method Summary collapse
-
#initialize(delegate, interfaces = {}) ⇒ Proxy
constructor
A new instance of Proxy.
- #respond_to?(symbol, include_private = false) ⇒ Boolean
Constructor Details
#initialize(delegate, interfaces = {}) ⇒ Proxy
Returns a new instance of Proxy.
31 32 33 34 |
# File 'lib/edango/di/proxy.rb', line 31 def initialize(delegate, interfaces = {}) @delegate = delegate @interfaces = interfaces end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
42 43 44 45 46 47 48 49 50 |
# File 'lib/edango/di/proxy.rb', line 42 def method_missing(name, *args, &block) interface = @interfaces[name.intern()] unless interface.nil? interface.call(@delegate, *args, &block) else @delegate.send(name, *args, &block) end end |
Instance Attribute Details
#delegate ⇒ Object (readonly)
Returns the value of attribute delegate.
29 30 31 |
# File 'lib/edango/di/proxy.rb', line 29 def delegate @delegate end |
#interfaces ⇒ Object (readonly)
Returns the value of attribute interfaces.
29 30 31 |
# File 'lib/edango/di/proxy.rb', line 29 def interfaces @interfaces end |
Instance Method Details
#respond_to?(symbol, include_private = false) ⇒ Boolean
36 37 38 39 |
# File 'lib/edango/di/proxy.rb', line 36 def respond_to?(symbol, include_private=false) @delegate.respond_to?(symbol, include_private) || @interfaces.has_key?(symbol) end |