Class: ObjectProxy
- Inherits:
-
Object
show all
- Defined in:
- lib/object_proxy.rb
Constant Summary
collapse
- SAFE_METHODS =
[:__id__, :__send__, :nil, :nil?, :send, :send!, :proxy_class, :proxy_respond_to?, :object_id]
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ObjectProxy.
16
17
18
|
# File 'lib/object_proxy.rb', line 16
def initialize(target)
@target = target
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
delegate nearly all method calls to the @target object
40
41
42
|
# File 'lib/object_proxy.rb', line 40
def method_missing(method, *args, &block)
target.send(method, *args, &block)
end
|
Instance Method Details
#inspect ⇒ Object
defining this explicitly to make pp.rb happy
33
34
35
|
# File 'lib/object_proxy.rb', line 33
def inspect
@target.inspect
end
|
#is_object_proxy? ⇒ Boolean
20
21
22
|
# File 'lib/object_proxy.rb', line 20
def is_object_proxy?
true
end
|
#proxy_respond_to? ⇒ Object
10
|
# File 'lib/object_proxy.rb', line 10
alias_method :proxy_respond_to?, :respond_to?
|
#respond_to?(*args) ⇒ Boolean
28
29
30
|
# File 'lib/object_proxy.rb', line 28
def respond_to?(*args)
proxy_respond_to?(*args) || target.respond_to?(*args)
end
|
#target ⇒ Object
24
25
26
|
# File 'lib/object_proxy.rb', line 24
def target
@target
end
|