Class: Grammar::Ruby::Code::And

Inherits:
List show all
Defined in:
lib/grammar/ruby/code.rb

Constant Summary

Constants inherited from Grammar::Ruby::Code

False, FalseTerminator, Implicit, Nil, Self, True

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from List

#_always, #_codes, #_lines, #_operator0, #_paren, #initialize

Methods inherited from Grammar::Ruby::Code

[], #_always, #_assign, #_classname, #_code_self, #_codes, #_data, #_def, #_dot, #_else, #_ensure, #_equal, #_immediate, #_inspect, #_lines, #_locals, #_not, #_question, #_rcond, #_rescue, #_ror, #_rstep, #_splat, #_step, #_to_block, #_until, #_while, #initialize, #method_missing

Constructor Details

This class inherits a constructor from Grammar::Ruby::Code::List

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Grammar::Ruby::Code

Class Method Details

.new(operands) ⇒ Object



528
529
530
# File 'lib/grammar/ruby/code.rb', line 528

def self.new(operands)
    (operands.size==1) ? operands[0] : super
end

Instance Method Details

#_andObject

:yield:



537
538
539
540
# File 'lib/grammar/ruby/code.rb', line 537

def _and # :yield:
    _never ? self :
    (yield._rand(@operands); self)
end

#_mid(before) ⇒ Object



562
563
564
565
566
567
568
569
# File 'lib/grammar/ruby/code.rb', line 562

def _mid(before)
    @operands.pop._mid(@operands)
    if @operands.size==1
        @operands.first._mid(before)
    else
        before << self
    end
end

#_neverObject



534
535
536
# File 'lib/grammar/ruby/code.rb', line 534

def _never
    @operands.last._never
end

#_operatorObject



531
532
533
# File 'lib/grammar/ruby/code.rb', line 531

def _operator
    " && "
end

#_orObject

:yield:



546
547
548
549
550
551
552
553
# File 'lib/grammar/ruby/code.rb', line 546

def _or # :yield:
    after = yield
    last = @operands.last
    (!last._always||after._never) ? Or.new(after._ror(operands = [self])) : 
    after._unless(
        (@operands.size==2) ? @operands.first : (@operands.pop;self),
        last)
end

#_rand(before) ⇒ Object



541
542
543
544
545
# File 'lib/grammar/ruby/code.rb', line 541

def _rand(before)
    @operands[0] = before.pop._step(@operands[0]) if
        before.last._always
    before.concat(@operands)
end

#_unless(cond, yes) ⇒ Object



554
555
556
557
558
559
560
561
# File 'lib/grammar/ruby/code.rb', line 554

def _unless(cond, yes)
    if @operands.last._equal(yes)
        @operands.pop
        cond._or{self}._and{yes}
    else
        super
    end
end