Class: Plumbing::RubberDuck::Proxy
- Inherits:
-
Object
- Object
- Plumbing::RubberDuck::Proxy
- Defined in:
- lib/plumbing/rubber_duck/proxy.rb
Overview
Proxy object that forwards the duck-typed methods to the target object
Instance Attribute Summary collapse
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
-
#as(duck_type) ⇒ Plumbing::RubberDuck::Proxy
Convert the proxy to the given duck-type, ensuring that existing proxies are not duplicated.
-
#initialize(target, duck_type) ⇒ Proxy
constructor
A new instance of Proxy.
Constructor Details
#initialize(target, duck_type) ⇒ Proxy
Returns a new instance of Proxy.
7 8 9 10 |
# File 'lib/plumbing/rubber_duck/proxy.rb', line 7 def initialize target, duck_type @target = target @duck_type = duck_type end |
Instance Attribute Details
#target ⇒ Object (readonly)
Returns the value of attribute target.
5 6 7 |
# File 'lib/plumbing/rubber_duck/proxy.rb', line 5 def target @target end |
Instance Method Details
#as(duck_type) ⇒ Plumbing::RubberDuck::Proxy
Convert the proxy to the given duck-type, ensuring that existing proxies are not duplicated
14 15 16 |
# File 'lib/plumbing/rubber_duck/proxy.rb', line 14 def as duck_type (duck_type == @duck_type) ? self : duck_type.proxy_for(target) end |