Class: ObjectProxy

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

Constant Summary collapse

VERSION =
'1.0.1'
SAFE_METHODS =
[:__id__, :__send__, :nil, :nil?, :send, :send!, :proxy_class, :proxy_respond_to?]

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ ObjectProxy

Returns a new instance of ObjectProxy.



18
19
20
# File 'lib/object_proxy.rb', line 18

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



37
38
39
# File 'lib/object_proxy.rb', line 37

def method_missing(method, *args, &block)
  @target.send(method, *args, &block)
end

Instance Method Details

#is_object_proxy?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/object_proxy.rb', line 22

def is_object_proxy?
  true
end

#proxy_respond_to?Object



12
# File 'lib/object_proxy.rb', line 12

alias_method :proxy_respond_to?, :respond_to?

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/object_proxy.rb', line 30

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

#targetObject



26
27
28
# File 'lib/object_proxy.rb', line 26

def target
  @target
end