Class: Optimus::ParsedCalculator::BinaryExpr
- 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
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#op ⇒ Object
readonly
Returns the value of attribute op.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
Instance Method Summary collapse
- #evaluate(*args) ⇒ Object
-
#initialize(left, op, right) ⇒ BinaryExpr
constructor
A new instance of BinaryExpr.
- #to_s ⇒ Object
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
#left ⇒ Object (readonly)
Returns the value of attribute left.
59 60 61 |
# File 'lib/expression_parser/expressions.rb', line 59 def left @left end |
#op ⇒ Object (readonly)
Returns the value of attribute op.
59 60 61 |
# File 'lib/expression_parser/expressions.rb', line 59 def op @op end |
#right ⇒ Object (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_s ⇒ Object
66 67 68 |
# File 'lib/expression_parser/expressions.rb', line 66 def to_s "(#{@left} #{@op} #{@right})" end |