Class: Kalc::Ast::Arithmetic
- Inherits:
-
Object
- Object
- Kalc::Ast::Arithmetic
- Defined in:
- lib/kalc/ast.rb
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
Instance Method Summary collapse
- #eval(context) ⇒ Object
-
#initialize(left, right, operator) ⇒ Arithmetic
constructor
A new instance of Arithmetic.
Constructor Details
#initialize(left, right, operator) ⇒ Arithmetic
Returns a new instance of Arithmetic.
140 141 142 143 144 |
# File 'lib/kalc/ast.rb', line 140 def initialize(left, right, operator) @left = left @right = right @operator = operator end |
Instance Attribute Details
#left ⇒ Object (readonly)
Returns the value of attribute left.
136 137 138 |
# File 'lib/kalc/ast.rb', line 136 def left @left end |
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
138 139 140 |
# File 'lib/kalc/ast.rb', line 138 def operator @operator end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
137 138 139 |
# File 'lib/kalc/ast.rb', line 137 def right @right end |
Instance Method Details
#eval(context) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/kalc/ast.rb', line 146 def eval(context) case @operator.to_s.strip when '&&' @left && @right when 'and' @left && @right when '||' @left || @right when 'or' @left || @right when '<=' @left <= @right when '>=' @left >= @right when '=' @left == @right when '==' @left == @right when '!=' @left != @right when '-' @left - @right when '+' @left + @right when '^' @left ** @right when '*' @left * @right when '/' @left / @right when '%' @left % @right when '<' @left < @right when '>' @left > @right end end |