Class: Dentaku::AST::Modulo

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

Instance Attribute Summary

Attributes inherited from Operation

#left, #right

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Arithmetic

#type

Methods inherited from Operation

#dependencies, right_associative?

Methods inherited from Node

arity, #dependencies

Constructor Details

#initialize(left, right) ⇒ Modulo

Returns a new instance of Modulo.



89
90
91
92
93
94
95
96
# File 'lib/dentaku/ast/arithmetic.rb', line 89

def initialize(left, right)
  @left  = left
  @right = right

  unless (valid_node?(left) || left.nil?) && valid_node?(right)
    fail ParseError, "#{ self.class } requires numeric operands"
  end
end

Class Method Details

.precedenceObject



114
115
116
# File 'lib/dentaku/ast/arithmetic.rb', line 114

def self.precedence
  20
end

Instance Method Details

#operatorObject



110
111
112
# File 'lib/dentaku/ast/arithmetic.rb', line 110

def operator
  :%
end

#percent?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/dentaku/ast/arithmetic.rb', line 98

def percent?
  left.nil?
end

#value(context = {}) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/dentaku/ast/arithmetic.rb', line 102

def value(context={})
  if percent?
    cast(right.value(context)) * 0.01
  else
    super
  end
end