Class: Grammar::Ruby::Code::While

Inherits:
Grammar::Ruby::Code show all
Defined in:
lib/grammar/ruby/code.rb

Direct Known Subclasses

Until

Constant Summary

Constants inherited from Grammar::Ruby::Code

False, FalseTerminator, Implicit, Nil, Self, True

Instance Method Summary collapse

Methods inherited from Grammar::Ruby::Code

[], #_and, #_assign, #_classname, #_code_self, #_data, #_def, #_dot, #_else, #_ensure, #_equal, #_immediate, #_inspect, #_locals, #_mid, #_not, #_or, #_question, #_rand, #_rcond, #_rescue, #_ror, #_rstep, #_splat, #_step, #_to_block, #_unless, #_until, #_while, #method_missing

Constructor Details

#initialize(condition, body = nil) ⇒ While

Returns a new instance of While.



985
986
987
988
# File 'lib/grammar/ruby/code.rb', line 985

def initialize(condition, body=nil)
    @condition = condition
    @body = body && body._mid([])[0]
end

Dynamic Method Handling

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

Instance Method Details

#_alwaysObject



1014
1015
1016
# File 'lib/grammar/ruby/code.rb', line 1014

def _always
    false
end

#_codesObject



989
990
991
992
993
# File 'lib/grammar/ruby/code.rb', line 989

def _codes
    codes = [@condition]
    codes << @body if @body
    codes
end

#_headerObject



994
995
996
# File 'lib/grammar/ruby/code.rb', line 994

def _header
    "while"
end

#_lines(text, indent = 0, op = nil, maxlen = 72) ⇒ Object



997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
# File 'lib/grammar/ruby/code.rb', line 997

def _lines(text, indent=0, op=nil, maxlen=72)
    (last = text.last).concat(_header) << ?\(
    single = @condition._lines(text, indent+3, nil, maxlen) or
    text << indent+2 << ""
    text.last << ?\)
    if @body
        text << indent+2 << ""
        @body._lines(text, indent+2, nil, maxlen)
        single = nil
    end
    if single
        text.last.concat("; end")
    else
        text << indent << "end"
        nil
    end
end

#_neverObject



1017
1018
1019
# File 'lib/grammar/ruby/code.rb', line 1017

def _never
    false
end