4 class Complex < PollCondition
19 @oper_stack.inject(true) { |acc, oper| acc & oper.valid? }
23 @oper_stack.each { |oper| oper.prepare }
26 def new_oper(kind, op)
27 oper = Condition.generate(kind, self.watch)
28 @oper_stack.push(oper)
34 @this = Condition.generate(kind, self.watch)
35 yield @this if block_given?
39 oper = new_oper(kind, 0x1)
40 yield oper if block_given?
44 oper = new_oper(kind, 0x5)
45 yield oper if block_given?
49 oper = new_oper(kind, 0x2)
50 yield oper if block_given?
54 oper = new_oper(kind, 0x6)
55 yield oper if block_given?
60 # Although this() makes sense semantically and therefore
61 # encourages easy-to-read conditions, being able to omit it
62 # allows for more DRY code in some cases, so we deal with a
63 # nil @this here by initially setting res to true or false,
64 # depending on whether the first operator used is AND or OR
66 if 0 < @op_stack[0] & AND
75 @op_stack.each do |op|
76 cond = @oper_stack.shift
77 eval "res " + ((0 < op & AND) ? "&&" : "||") + "= " + ((0 < op & NOT) ? "!" : "") + "cond.test"