Class: ZeevexProxy::Base
- Inherits:
- BasicObject
- Defined in:
- lib/zeevex_proxy/base.rb
Constant Summary
Constants inherited from BasicObject
ZeevexProxy::BasicObject::KEEP_METHODS
Instance Method Summary collapse
- #__getobj__ ⇒ Object
- #__substitute_self__(candidate, pself) ⇒ Object
-
#initialize(target, options = {}, &block) ⇒ Base
constructor
A new instance of Base.
-
#method_missing(name, *args, &block) ⇒ Object
if chainable method or returns “self” for some other reason, return this proxy instead.
Methods inherited from BasicObject
inherited, #object_id, #raise, remove_methods!
Constructor Details
#initialize(target, options = {}, &block) ⇒ Base
Returns a new instance of Base.
43 44 45 46 47 48 49 50 |
# File 'lib/zeevex_proxy/base.rb', line 43 def initialize(target, = {}, &block) super() @obj = @__proxy_object__ = target if block eigenclass = class << self; self; end eigenclass.__send__(:define_method, :method_missing, &block) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
if chainable method or returns “self” for some other reason, return this proxy instead
62 63 64 65 |
# File 'lib/zeevex_proxy/base.rb', line 62 def method_missing(name, *args, &block) obj = __getobj__ __substitute_self__(obj.__send__(name, *args, &block), obj) end |
Instance Method Details
#__getobj__ ⇒ Object
52 53 54 |
# File 'lib/zeevex_proxy/base.rb', line 52 def __getobj__ @__proxy_object__ end |
#__substitute_self__(candidate, pself) ⇒ Object
56 57 58 |
# File 'lib/zeevex_proxy/base.rb', line 56 def __substitute_self__(candidate, pself) candidate.__id__ == pself.__id__ ? self : candidate end |