Class: Kalc::Ast::Ops

Inherits:
Object
  • Object
show all
Defined in:
lib/kalc/ast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#leftObject (readonly)

Returns the value of attribute left.



118
119
120
# File 'lib/kalc/ast.rb', line 118

def left
  @left
end

#opsObject (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