Class: Yadriggy::Break

Inherits:
ASTnode show all
Includes:
AstHelper
Defined in:
lib/yadriggy/ast.rb

Overview

break, next, redo, or retry.

Instance Attribute Summary collapse

Attributes inherited from ASTnode

#parent, #usertype

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AstHelper

#has_tag?, #to_node, #to_nodes

Methods inherited from ASTnode

#add_child, #add_children, #const_value, #const_value_in_class, #get_context_class, #get_receiver_object, #is_proc?, #pretty_print, #root, #source_location, #source_location_string, #value, #value_in_class

Constructor Details

#initialize(sexp) ⇒ Break

Returns a new instance of Break.



1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
# File 'lib/yadriggy/ast.rb', line 1222

def initialize(sexp)
  @op = sexp[0]
  if @op == :break || @op == :next
    if sexp[1].size == 0
      @values = []
    else
      values = has_tag?(sexp[1], :args_add_block)[1]
      @values = to_nodes(values)
    end
    add_children(@values)
  else
    @values = []
  end
end

Instance Attribute Details

#opSymbol (readonly)

Returns :break, :next, :redo, or :retry.

Returns:

  • (Symbol)

    :break, :next, :redo, or :retry.



1216
1217
1218
# File 'lib/yadriggy/ast.rb', line 1216

def op
  @op
end

#valuesArray<ASTnode> (readonly)

Returns an array of the break/next arguments.

Returns:

  • (Array<ASTnode>)

    an array of the break/next arguments.



1218
1219
1220
# File 'lib/yadriggy/ast.rb', line 1218

def values
  @values
end

Class Method Details

.tagsObject



1220
# File 'lib/yadriggy/ast.rb', line 1220

def self.tags() [:break, :next, :redo, :retry] end

Instance Method Details

#accept(evaluator) ⇒ void

This method returns an undefined value.

A method for Visitor pattern.

Parameters:

  • evaluator (Eval)

    the visitor of Visitor pattern.



1240
1241
1242
# File 'lib/yadriggy/ast.rb', line 1240

def accept(evaluator)
  evaluator.break_out(self)
end