Class: Chelsy::For

Inherits:
Iteration show all
Defined in:
lib/chelsy/ast.rb

Overview

This class represents for iteration statement.

Instance Attribute Summary collapse

Attributes inherited from Iteration

#body, #condition

Attributes inherited from Element

#fragments, #post_fragments

Instance Method Summary collapse

Constructor Details

#initialize(init_stmt = nil, condition_expr = nil, loop_expr = nil, body_stmt = nil, **rest) {|Chelsy::Block| ... } ⇒ For

Initialize iteration statement with its condition and iteration body statement. You can pass an optional code block which takes Block instance can be used to construct iteration body statements.

Parameters:

  • condition_expr (defaults to: nil)

    an expression which express condition

  • body_stmt (defaults to: nil)

    iteration body statement

  • init_stmt (defaults to: nil)

    initialization statement

  • loop_expr (defaults to: nil)

    loop expression is performed each iteration

Yields:

Raises:

  • (ArgumentError)

    Given neither body_stmt nor code block



1067
1068
1069
1070
1071
1072
# File 'lib/chelsy/ast.rb', line 1067

def initialize(init_stmt=nil, condition_expr=nil, loop_expr=nil, body_stmt=nil, **rest)
  @init = Syntax::BlockItem::ensure(init_stmt) if init_stmt
  @loop = Syntax::Expr.ensure(loop_expr) if loop_expr

  super condition_expr, body_stmt, **rest
end

Instance Attribute Details

#initObject (readonly)

Returns the value of attribute init.



1062
1063
1064
# File 'lib/chelsy/ast.rb', line 1062

def init
  @init
end

#loopObject (readonly)

Returns the value of attribute loop.



1062
1063
1064
# File 'lib/chelsy/ast.rb', line 1062

def loop
  @loop
end