Module: Cadenza::Context::FunctionalVariables
- Included in:
- Cadenza::Context
- Defined in:
- lib/cadenza/context/functional_variables.rb
Instance Attribute Summary collapse
-
#functional_variables ⇒ Hash
readonly
The functional variable names mapped to their implementing procs.
Instance Method Summary collapse
-
#alias_functional_variable(original_name, alias_name) ⇒ Object
creates an alias of the given functional variable name under a different name.
-
#define_functional_variable(name) {|Context, *args| ... } ⇒ Object
defines a functional variable proc with the given name.
-
#evaluate_functional_variable(name, params = []) ⇒ Object
calls the defined functional variable proc with the given parameters and returns the result.
-
#lookup_functional_variable(name) ⇒ Proc
looks up the functional variable by name.
Instance Attribute Details
#functional_variables ⇒ Hash (readonly)
Returns the functional variable names mapped to their implementing procs.
10 11 12 |
# File 'lib/cadenza/context/functional_variables.rb', line 10 def functional_variables @functional_variables ||= {} end |
Instance Method Details
#alias_functional_variable(original_name, alias_name) ⇒ Object
creates an alias of the given functional variable name under a different name
40 41 42 |
# File 'lib/cadenza/context/functional_variables.rb', line 40 def alias_functional_variable(original_name, alias_name) define_functional_variable alias_name, &lookup_functional_variable(original_name) end |
#define_functional_variable(name) {|Context, *args| ... } ⇒ Object
defines a functional variable proc with the given name
29 30 31 32 |
# File 'lib/cadenza/context/functional_variables.rb', line 29 def define_functional_variable(name, &block) functional_variables[name.to_sym] = block nil end |
#evaluate_functional_variable(name, params = []) ⇒ Object
calls the defined functional variable proc with the given parameters and returns the result.
52 53 54 |
# File 'lib/cadenza/context/functional_variables.rb', line 52 def evaluate_functional_variable(name, params=[]) lookup_functional_variable(name).call([self] + params) end |
#lookup_functional_variable(name) ⇒ Proc
looks up the functional variable by name
19 20 21 |
# File 'lib/cadenza/context/functional_variables.rb', line 19 def lookup_functional_variable(name) functional_variables.fetch(name.to_sym) { raise FunctionalVariableNotDefinedError.new("undefined functional variable '#{name}'") } end |