Module: TyranoDsl::ParsingWords::UpdateVariable

Includes:
ParsingWordsModule
Defined in:
lib/tyrano_dsl/parsing_words/update_variable.rb

Constant Summary collapse

VALID_OPERATORS =
[
    '=',
    '+=',
    '-=',
    '*=',
    '/=',
    '%=',
]

Instance Method Summary collapse

Instance Method Details

#update_variable(variable, operator, value) ⇒ void

This method returns an undefined value.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/tyrano_dsl/parsing_words/update_variable.rb', line 22

def update_variable(variable, operator, value)
  check_variable_exist(variable)
  if value.is_a?(String) || value.is_a?(Symbol)
    check_variable_exist(value)
  end
  unless VALID_OPERATORS.include? operator
    raise TyranoDsl::TyranoException, "Unknown operator [#{operator}]"
  end
  add_parsed_word(
      TyranoDsl::Vocabulary::UPDATE_VARIABLE,
      variable: variable,
      operator: operator,
      value: value
  )
end