Class: Dentaku::AST::Modulo

Inherits:
Arithmetic show all
Defined in:
lib/dentaku/ast/arithmetic.rb

Constant Summary

Constants inherited from Arithmetic

Arithmetic::DECIMAL, Arithmetic::INTEGER

Instance Attribute Summary

Attributes inherited from Operation

#left, #right

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Arithmetic

#initialize, #type

Methods inherited from Operation

#accept, #dependencies, #display_operator, #initialize, max_param_count, min_param_count, #operator_spacing, right_associative?

Methods inherited from Node

#dependencies, #name, #type

Constructor Details

This class inherits a constructor from Dentaku::AST::Arithmetic

Class Method Details

.arityObject



219
220
221
# File 'lib/dentaku/ast/arithmetic.rb', line 219

def self.arity
  2
end

.precedenceObject



223
224
225
# File 'lib/dentaku/ast/arithmetic.rb', line 223

def self.precedence
  20
end

.resolve_class(next_token) ⇒ Object



227
228
229
# File 'lib/dentaku/ast/arithmetic.rb', line 227

def self.resolve_class(next_token)
  next_token.nil? || next_token.operator? || next_token.close? ? Percentage : self
end

Instance Method Details

#operatorObject



231
232
233
# File 'lib/dentaku/ast/arithmetic.rb', line 231

def operator
  :%
end

#value(context = {}) ⇒ Object



235
236
237
238
239
240
# File 'lib/dentaku/ast/arithmetic.rb', line 235

def value(context = {})
  r = decimal(cast(right.value(context)))
  raise Dentaku::ZeroDivisionError if r.zero?

  cast(cast(left.value(context)) % r)
end