Class: Dentaku::AST::Arithmetic
- Defined in:
- lib/dentaku/ast/arithmetic.rb
Direct Known Subclasses
Addition, Division, Exponentiation, Modulo, Multiplication, Negation, Subtraction
Instance Attribute Summary
Attributes inherited from Operation
Instance Method Summary collapse
-
#initialize ⇒ Arithmetic
constructor
A new instance of Arithmetic.
- #operator ⇒ Object
- #type ⇒ Object
- #value(context = {}) ⇒ Object
Methods inherited from Operation
#dependencies, right_associative?
Methods inherited from Node
arity, #dependencies, peek, precedence
Constructor Details
#initialize ⇒ Arithmetic
Returns a new instance of Arithmetic.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/dentaku/ast/arithmetic.rb', line 8 def initialize(*) super unless valid_left? raise NodeError.new(:numeric, left.type, :left), "#{self.class} requires numeric operands" end unless valid_right? raise NodeError.new(:numeric, right.type, :right), "#{self.class} requires numeric operands" end end |
Instance Method Details
#operator ⇒ Object
25 26 27 |
# File 'lib/dentaku/ast/arithmetic.rb', line 25 def operator raise NotImplementedError end |
#type ⇒ Object
21 22 23 |
# File 'lib/dentaku/ast/arithmetic.rb', line 21 def type :numeric end |
#value(context = {}) ⇒ Object
29 30 31 32 33 |
# File 'lib/dentaku/ast/arithmetic.rb', line 29 def value(context = {}) l = cast(left.value(context)) r = cast(right.value(context)) l.public_send(operator, r) end |