# File lib/god/conditions/complex.rb, line 38 def and(kind) oper = new_oper(kind, 0x1) yield oper if block_given? end
# File lib/god/conditions/complex.rb, line 43 def and_not(kind) oper = new_oper(kind, 0x5) yield oper if block_given? end
# File lib/god/conditions/complex.rb, line 26 def new_oper(kind, op) oper = Condition.generate(kind, self.watch) @oper_stack.push(oper) @op_stack.push(op) oper end
# File lib/god/conditions/complex.rb, line 48 def or(kind) oper = new_oper(kind, 0x2) yield oper if block_given? end
# File lib/god/conditions/complex.rb, line 53 def or_not(kind) oper = new_oper(kind, 0x6) yield oper if block_given? end
# File lib/god/conditions/complex.rb, line 22 def prepare @oper_stack.each { |oper| oper.prepare } end
# File lib/god/conditions/complex.rb, line 58 def test if @this.nil? # Although this() makes sense semantically and therefore # encourages easy-to-read conditions, being able to omit it # allows for more DRY code in some cases, so we deal with a # nil @this here by initially setting res to true or false, # depending on whether the first operator used is AND or OR # respectively. if 0 < @op_stack[0] & AND res = true else res = false end else res = @this.test end @op_stack.each do |op| cond = @oper_stack.shift eval "res " + ((0 < op & AND) ? "&&" : "||") + "= " + ((0 < op & NOT) ? "!" : "") + "cond.test" @oper_stack.push cond end res end
Generated with the Darkfish Rdoc Generator 2.