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.
120 121 122 123 |
# File 'lib/kalc/ast.rb', line 120 def initialize(left, ops) @left = left @ops = ops end |
Instance Attribute Details
#left ⇒ Object (readonly)
Returns the value of attribute left.
117 118 119 |
# File 'lib/kalc/ast.rb', line 117 def left @left end |
#ops ⇒ Object (readonly)
Returns the value of attribute ops.
118 119 120 |
# File 'lib/kalc/ast.rb', line 118 def ops @ops end |
Instance Method Details
#eval(context) ⇒ Object
125 126 127 128 129 130 |
# File 'lib/kalc/ast.rb', line 125 def eval(context) @ops.inject(@left.eval(context)) { |x, op| a = Arithmetic.new(x, op[:right].eval(context), op[:operator]) a.eval(context) } end |