Class: PortableExpressions::Environment

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Serializable

#to_json

Constructor Details

#initialize(**variables) ⇒ Environment

Returns a new instance of Environment.

Parameters:

  • variables (Hash)


12
13
14
# File 'lib/portable_expressions/environment.rb', line 12

def initialize(**variables)
  @variables = variables
end

Instance Attribute Details

#variablesObject (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_jsonObject



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

Parameters:



18
19
20
# File 'lib/portable_expressions/environment.rb', line 18

def evaluate(*objects)
  objects.map { |object| evaluate_one(object) }.last
end