Class: Rjq::AST::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/rjq/ast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(variables: {}, functions: {}, options: {}, current_path: [], binding_variable_paths: {}) ⇒ Context

Returns a new instance of Context.



10
11
12
13
14
15
16
# File 'lib/rjq/ast.rb', line 10

def initialize(variables: {}, functions: {}, options: {}, current_path: [], binding_variable_paths: {})
  @variables = variables
  @functions = functions
  @options = options
  @current_path = current_path
  @binding_variable_paths = binding_variable_paths
end

Instance Attribute Details

#binding_variable_pathsObject (readonly)

Returns the value of attribute binding_variable_paths.



8
9
10
# File 'lib/rjq/ast.rb', line 8

def binding_variable_paths
  @binding_variable_paths
end

#current_pathObject (readonly)

Returns the value of attribute current_path.



8
9
10
# File 'lib/rjq/ast.rb', line 8

def current_path
  @current_path
end

#functionsObject (readonly)

Returns the value of attribute functions.



8
9
10
# File 'lib/rjq/ast.rb', line 8

def functions
  @functions
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/rjq/ast.rb', line 8

def options
  @options
end

#variablesObject (readonly)

Returns the value of attribute variables.



8
9
10
# File 'lib/rjq/ast.rb', line 8

def variables
  @variables
end

Instance Method Details

#with_function(name, arity, definition) ⇒ Object



22
23
24
# File 'lib/rjq/ast.rb', line 22

def with_function(name, arity, definition)
  copy(functions: functions.merge([name, arity] => definition))
end

#with_functions(new_functions) ⇒ Object



26
27
28
# File 'lib/rjq/ast.rb', line 26

def with_functions(new_functions)
  copy(functions: new_functions)
end

#with_options(new_options) ⇒ Object



34
35
36
# File 'lib/rjq/ast.rb', line 34

def with_options(new_options)
  copy(options: new_options)
end

#with_path_state(current_path:, variables: binding_variable_paths) ⇒ Object



30
31
32
# File 'lib/rjq/ast.rb', line 30

def with_path_state(current_path:, variables: binding_variable_paths)
  copy(current_path: current_path, binding_variable_paths: variables)
end

#with_variable(name, value) ⇒ Object



18
19
20
# File 'lib/rjq/ast.rb', line 18

def with_variable(name, value)
  copy(variables: variables.merge(name => value))
end