Class: ObjectProxy

Inherits:
Object
  • 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

#initialize(target) ⇒ ObjectProxy

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 (protected)

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

#inspectObject

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

Returns:

  • (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

Returns:

  • (Boolean)


28
29
30
# File 'lib/object_proxy.rb', line 28

def respond_to?(*args)
  proxy_respond_to?(*args) || target.respond_to?(*args)
end

#targetObject



24
25
26
# File 'lib/object_proxy.rb', line 24

def target
  @target
end