Class: Dentaku::AST::Arithmetic
- Defined in:
- lib/dentaku/ast/arithmetic.rb
Direct Known Subclasses
Addition, Division, Exponentiation, Modulo, Multiplication, Negation, Percentage, Subtraction
Constant Summary collapse
- DECIMAL =
/\A-?\d*\.\d+\z/.freeze
- INTEGER =
/\A-?\d+\z/.freeze
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
#accept, #dependencies, #display_operator, max_param_count, min_param_count, right_associative?
Methods inherited from Node
arity, #dependencies, #name, precedence, resolve_class
Constructor Details
#initialize ⇒ Arithmetic
Returns a new instance of Arithmetic.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dentaku/ast/arithmetic.rb', line 12 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
30 31 32 |
# File 'lib/dentaku/ast/arithmetic.rb', line 30 def operator raise NotImplementedError end |
#type ⇒ Object
26 27 28 |
# File 'lib/dentaku/ast/arithmetic.rb', line 26 def type :numeric end |
#value(context = {}) ⇒ Object
34 35 36 |
# File 'lib/dentaku/ast/arithmetic.rb', line 34 def value(context = {}) calculate(left.value(context), right.value(context)) end |