Class: Optimus::ParsedCalculator::BinaryExpr

Inherits:
Expr
  • Object
show all
Includes:
Evaluators::Binary
Defined in:
lib/expression_parser/expressions.rb

Constant Summary

Constants included from Evaluators::Binary

Evaluators::Binary::And, Evaluators::Binary::Concat, Evaluators::Binary::Div, Evaluators::Binary::Equals, Evaluators::Binary::GreaterThan, Evaluators::Binary::GreaterThanEquals, Evaluators::Binary::LessThan, Evaluators::Binary::LessThanEquals, Evaluators::Binary::Minus, Evaluators::Binary::Mod, Evaluators::Binary::NotEquals, Evaluators::Binary::OpTable, Evaluators::Binary::Or, Evaluators::Binary::Plus, Evaluators::Binary::Times

Constants inherited from Expr

Expr::BINARY_OPERATORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Expr

#-@, #eq, #logical_and, #logical_not, #logical_or, #neq, #to_bool

Constructor Details

#initialize(left, op, right) ⇒ BinaryExpr

Returns a new instance of BinaryExpr.



60
61
62
63
64
# File 'lib/expression_parser/expressions.rb', line 60

def initialize(left, op, right)
  @left = left
  @op = op
  @right = right
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



59
60
61
# File 'lib/expression_parser/expressions.rb', line 59

def left
  @left
end

#opObject (readonly)

Returns the value of attribute op.



59
60
61
# File 'lib/expression_parser/expressions.rb', line 59

def op
  @op
end

#rightObject (readonly)

Returns the value of attribute right.



59
60
61
# File 'lib/expression_parser/expressions.rb', line 59

def right
  @right
end

Instance Method Details

#evaluate(*args) ⇒ Object



70
71
72
73
74
# File 'lib/expression_parser/expressions.rb', line 70

def evaluate(*args)
  lval = @left.evaluate(*args)
  rval = @right.evaluate(*args)
  return OpTable[@op].call(lval, rval)
end

#to_sObject



66
67
68
# File 'lib/expression_parser/expressions.rb', line 66

def to_s
  "(#{@left} #{@op} #{@right})"
end