Class: S4tUtils::ArgForwarder
- Inherits:
-
Object
- Object
- S4tUtils::ArgForwarder
- Defined in:
- lib/s4t-utils/hacks.rb
Overview
An ArgForwarder is associated with a target. It forwards messages sent to it to the target, passing along any arguments to the method. So far, so boring. But an ArgForwarder is also created with some added_args. When the ArgForwarder forwards, it prepends those added_args to the message’s given arguments.
array = []
forwarder = ArgForwarder.new(array, 5)
forwarder.push
assert_equal([5], array)
Instance Method Summary collapse
-
#initialize(target, *added_args) ⇒ ArgForwarder
constructor
A new instance of ArgForwarder.
-
#method_missing(method, *args) ⇒ Object
:nodoc:.
Constructor Details
#initialize(target, *added_args) ⇒ ArgForwarder
Returns a new instance of ArgForwarder.
47 48 49 50 |
# File 'lib/s4t-utils/hacks.rb', line 47 def initialize(target, *added_args) @target = target @added_args = added_args end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
:nodoc:
52 53 54 |
# File 'lib/s4t-utils/hacks.rb', line 52 def method_missing(method, *args) # :nodoc: @target.send(method, *(@added_args + args)) end |