Class: Kalc::Ast::Ops
- Inherits:
-
Object
- Object
- Kalc::Ast::Ops
- Defined in:
- lib/kalc/ast.rb
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#ops ⇒ Object
readonly
Returns the value of attribute ops.
Instance Method Summary collapse
- #eval(context) ⇒ Object
-
#initialize(left, ops) ⇒ Ops
constructor
A new instance of Ops.
Constructor Details
#initialize(left, ops) ⇒ Ops
Returns a new instance of Ops.
121 122 123 124 |
# File 'lib/kalc/ast.rb', line 121 def initialize(left, ops) @left = left @ops = ops end |
Instance Attribute Details
#left ⇒ Object (readonly)
Returns the value of attribute left.
118 119 120 |
# File 'lib/kalc/ast.rb', line 118 def left @left end |
#ops ⇒ Object (readonly)
Returns the value of attribute ops.
119 120 121 |
# File 'lib/kalc/ast.rb', line 119 def ops @ops end |
Instance Method Details
#eval(context) ⇒ Object
126 127 128 129 130 131 |
# File 'lib/kalc/ast.rb', line 126 def eval(context) @ops.inject(@left.eval(context)) { |x, op| a = Arithmetic.new(x, op[:right].eval(context), op[:operator]) a.eval(context) } end |