Class: Patm::Pattern::LogicalOp
Direct Known Subclasses
And, Or
Instance Method Summary
collapse
#&, #[], build_from, #compile, #execute, #opt
Constructor Details
#initialize(pats, op_str) ⇒ LogicalOp
Returns a new instance of LogicalOp.
348
349
350
351
|
# File 'lib/patm.rb', line 348
def initialize(pats, op_str)
@pats = pats
@op_str = op_str
end
|
Instance Method Details
#compile_internal(free_index, target_name = "_obj") ⇒ Object
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
|
# File 'lib/patm.rb', line 352
def compile_internal(free_index, target_name = "_obj")
srcs = []
i = free_index
ctxs = []
@pats.each do|pat|
s, c, i = pat.compile_internal(i, target_name)
if !s && @op_str == '||' srcs << 'true'
else
srcs << s
end
ctxs << c
end
[
srcs.compact.map{|s| "(#{s})" }.join(" #{@op_str}\n"),
ctxs.flatten(1),
i
]
end
|
#opt? ⇒ Boolean
375
376
377
|
# File 'lib/patm.rb', line 375
def opt?
@pats.any?(&:opt?)
end
|
#rest? ⇒ Boolean
372
373
374
|
# File 'lib/patm.rb', line 372
def rest?
@pats.any?(&:rest?)
end
|