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
max_param_count, min_param_count, right_associative?
Methods inherited from Node
#type
Constructor Details
#initialize(left, right = nil) ⇒ Modulo
Returns a new instance of Modulo.
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/dentaku/ast/arithmetic.rb', line 167
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
158
159
160
|
# File 'lib/dentaku/ast/arithmetic.rb', line 158
def self.arity
@arity
end
|
.peek(input) ⇒ Object
162
163
164
165
|
# File 'lib/dentaku/ast/arithmetic.rb', line 162
def self.peek(input)
@arity = 1
@arity = 2 if input.length > 1
end
|
.precedence ⇒ Object
209
210
211
|
# File 'lib/dentaku/ast/arithmetic.rb', line 209
def self.precedence
20
end
|
Instance Method Details
#dependencies(context = {}) ⇒ Object
185
186
187
188
189
190
191
|
# File 'lib/dentaku/ast/arithmetic.rb', line 185
def dependencies(context = {})
if percent?
@right.dependencies(context)
else
super
end
end
|
#operator ⇒ Object
205
206
207
|
# File 'lib/dentaku/ast/arithmetic.rb', line 205
def operator
:%
end
|
#percent? ⇒ Boolean
193
194
195
|
# File 'lib/dentaku/ast/arithmetic.rb', line 193
def percent?
left.nil?
end
|
#valid_left? ⇒ Boolean
213
214
215
|
# File 'lib/dentaku/ast/arithmetic.rb', line 213
def valid_left?
valid_node?(left) || left.nil?
end
|
#value(context = {}) ⇒ Object
197
198
199
200
201
202
203
|
# File 'lib/dentaku/ast/arithmetic.rb', line 197
def value(context = {})
if percent?
cast(right.value(context)) * 0.01
else
super
end
end
|