Class: PortableExpressions::Environment
- Inherits:
-
Object
- Object
- PortableExpressions::Environment
- Includes:
- Serializable
- Defined in:
- lib/portable_expressions/environment.rb
Overview
The ‘Environment` holds state in the form of a `variables` hash and can evaluate `Expressions`, `Scalars`, and `Variables` within a context.
Instance Attribute Summary collapse
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#evaluate(*objects) ⇒ Object
Evaluates each object.
-
#initialize(**variables) ⇒ Environment
constructor
A new instance of Environment.
Methods included from Serializable
Constructor Details
#initialize(**variables) ⇒ Environment
Returns a new instance of Environment.
12 13 14 |
# File 'lib/portable_expressions/environment.rb', line 12 def initialize(**variables) @variables = variables end |
Instance Attribute Details
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
9 10 11 |
# File 'lib/portable_expressions/environment.rb', line 9 def variables @variables end |
Instance Method Details
#as_json ⇒ Object
22 23 24 |
# File 'lib/portable_expressions/environment.rb', line 22 def as_json super.merge(variables: variables) end |
#evaluate(*objects) ⇒ Object
Evaluates each object. Returns the value of the last object
18 19 20 |
# File 'lib/portable_expressions/environment.rb', line 18 def evaluate(*objects) objects.map { |object| evaluate_one(object) }.last end |