Class: Chelsy::Switch

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

Overview

=== 6.8.4.2 Theswitchstatement

Instance Attribute Summary collapse

Attributes inherited from Element

#fragments, #post_fragments

Instance Method Summary collapse

Constructor Details

#initialize(expr, stmt = nil, **rest, &block) ⇒ Switch

Returns a new instance of Switch.



985
986
987
988
989
990
991
992
993
994
995
996
997
998
# File 'lib/chelsy/ast.rb', line 985

def initialize(expr, stmt=nil, **rest, &block)
  @expr = Syntax::Expr.ensure(expr)

  if stmt
    @stmt = Syntax::Stmt.ensure(stmt)
  elsif block
    @stmt = Block.new
    block.call(@stmt)
  else
    raise ArgumentError, "missing body statement"
  end

  super **rest
end

Instance Attribute Details

#exprObject (readonly)

Returns the value of attribute expr.



983
984
985
# File 'lib/chelsy/ast.rb', line 983

def expr
  @expr
end

#stmtObject (readonly)

Returns the value of attribute stmt.



983
984
985
# File 'lib/chelsy/ast.rb', line 983

def stmt
  @stmt
end