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.
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/dentaku/ast/arithmetic.rb', line 162
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
153
154
155
|
# File 'lib/dentaku/ast/arithmetic.rb', line 153
def self.arity
@arity
end
|
.peek(input) ⇒ Object
157
158
159
160
|
# File 'lib/dentaku/ast/arithmetic.rb', line 157
def self.peek(input)
@arity = 1
@arity = 2 if input.length > 1
end
|
.precedence ⇒ Object
204
205
206
|
# File 'lib/dentaku/ast/arithmetic.rb', line 204
def self.precedence
20
end
|
Instance Method Details
#dependencies(context = {}) ⇒ Object
180
181
182
183
184
185
186
|
# File 'lib/dentaku/ast/arithmetic.rb', line 180
def dependencies(context = {})
if percent?
@right.dependencies(context)
else
super
end
end
|
#operator ⇒ Object
200
201
202
|
# File 'lib/dentaku/ast/arithmetic.rb', line 200
def operator
:%
end
|
#percent? ⇒ Boolean
188
189
190
|
# File 'lib/dentaku/ast/arithmetic.rb', line 188
def percent?
left.nil?
end
|
#valid_left? ⇒ Boolean
208
209
210
|
# File 'lib/dentaku/ast/arithmetic.rb', line 208
def valid_left?
valid_node?(left) || left.nil?
end
|
#value(context = {}) ⇒ Object
192
193
194
195
196
197
198
|
# File 'lib/dentaku/ast/arithmetic.rb', line 192
def value(context = {})
if percent?
cast(right.value(context)) * 0.01
else
super
end
end
|