Class: Calculi::Caller
- Inherits:
-
Object
- Object
- Calculi::Caller
- Defined in:
- lib/calculi/caller.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#originator ⇒ Object
readonly
Returns the value of attribute originator.
Instance Method Summary collapse
- #call(other_function_key, *args) ⇒ Object (also: #[])
- #chain(*other_functions) ⇒ Object
-
#initialize(originator, context) ⇒ Caller
constructor
A new instance of Caller.
Constructor Details
#initialize(originator, context) ⇒ Caller
Returns a new instance of Caller.
13 14 15 16 |
# File 'lib/calculi/caller.rb', line 13 def initialize(originator, context) @originator = originator @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
8 9 10 |
# File 'lib/calculi/caller.rb', line 8 def context @context end |
#originator ⇒ Object (readonly)
Returns the value of attribute originator.
4 5 6 |
# File 'lib/calculi/caller.rb', line 4 def originator @originator end |
Instance Method Details
#call(other_function_key, *args) ⇒ Object Also known as: []
18 19 20 21 22 |
# File 'lib/calculi/caller.rb', line 18 def call(other_function_key, *args) prevent_recursion! other_function_key fetch(other_function_key).call(context, *args) end |
#chain(*other_functions) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/calculi/caller.rb', line 26 def chain(*other_functions) other_functions.reduce(context) do |last_context, other_function_key| other_fn = fetch(other_function_key) other_fn.call last_context end end |