Class: Putter::Follower
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
Instance Method Summary collapse
- #add_method(method) ⇒ Object
-
#initialize(obj, options = {}) ⇒ Follower
constructor
A new instance of Follower.
- #method_missing(method, *args, &blk) ⇒ Object
Methods included from MethodCreator
Constructor Details
#initialize(obj, options = {}) ⇒ Follower
Returns a new instance of Follower.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/putter/follower.rb', line 7 def initialize(obj, ={}) @object = obj @proxy = MethodProxy.new begin @object.singleton_class.send(:prepend, proxy) rescue ::NoMethodError ::Kernel.raise ::Putter::BasicObjectError end @data = FollowerData.new(@object, @proxy, ) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &blk) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/putter/follower.rb', line 18 def method_missing(method, *args, &blk) if @data.add_method?(method) add_method(method) end if blk @object.send(method, *args, &blk) else @object.send(method, *args) end end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
5 6 7 |
# File 'lib/putter/follower.rb', line 5 def object @object end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
5 6 7 |
# File 'lib/putter/follower.rb', line 5 def proxy @proxy end |
Instance Method Details
#add_method(method) ⇒ Object
30 31 32 33 34 |
# File 'lib/putter/follower.rb', line 30 def add_method(method) proxy_method_data = ProxyMethodData.new(label: @data.label, method: method) add_putter_method_to_proxy(@proxy, proxy_method_data) end |