Class: Dentaku::AST::Modulo
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
#dependencies
Constructor Details
#initialize(left, right = nil) ⇒ Modulo
Returns a new instance of Modulo.
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'lib/dentaku/ast/arithmetic.rb', line 144
def initialize(left, right = nil)
if right
@left = left
@right = right
else
@right = left
end
unless valid_left?
raise NodeError.new(%i[numeric nil], left.type, :left),
"#{self.class} requires numeric operands or nil"
end
unless valid_right?
raise NodeError.new(:numeric, right.type, :right),
"#{self.class} requires numeric operands"
end
end
|
Class Method Details
.arity ⇒ Object
135
136
137
|
# File 'lib/dentaku/ast/arithmetic.rb', line 135
def self.arity
@arity
end
|
.peek(input) ⇒ Object
139
140
141
142
|
# File 'lib/dentaku/ast/arithmetic.rb', line 139
def self.peek(input)
@arity = 1
@arity = 2 if input.length > 1
end
|
.precedence ⇒ Object
178
179
180
|
# File 'lib/dentaku/ast/arithmetic.rb', line 178
def self.precedence
20
end
|
Instance Method Details
#operator ⇒ Object
174
175
176
|
# File 'lib/dentaku/ast/arithmetic.rb', line 174
def operator
:%
end
|
#percent? ⇒ Boolean
162
163
164
|
# File 'lib/dentaku/ast/arithmetic.rb', line 162
def percent?
left.nil?
end
|
#valid_left? ⇒ Boolean
182
183
184
|
# File 'lib/dentaku/ast/arithmetic.rb', line 182
def valid_left?
valid_node?(left) || left.nil?
end
|
#value(context = {}) ⇒ Object
166
167
168
169
170
171
172
|
# File 'lib/dentaku/ast/arithmetic.rb', line 166
def value(context = {})
if percent?
cast(right.value(context)) * 0.01
else
super
end
end
|