Class: Yadriggy::Block

Inherits:
Parameters show all
Defined in:
lib/yadriggy/ast.rb

Overview

Block.

Direct Known Subclasses

Lambda

Instance Attribute Summary collapse

Attributes inherited from Parameters

#block_param, #keywords, #optionals, #params, #params_after_rest, #rest_of_keywords, #rest_of_params

Attributes inherited from ASTnode

#parent, #usertype

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Parameters

#initialize_params

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) ⇒ Block

Returns a new instance of Block.



1382
1383
1384
1385
1386
1387
1388
1389
1390
# File 'lib/yadriggy/ast.rb', line 1382

def initialize(sexp)
  var = has_tag?(sexp[1], :block_var)
  if var.nil?
    params = nil
  else
    params = has_tag?(var[1], :params)
  end
  initialize_vars(params, sexp[2])
end

Instance Attribute Details

#bodyASTnode (readonly)

Returns the body.

Returns:



1376
1377
1378
# File 'lib/yadriggy/ast.rb', line 1376

def body
  @body
end

#rescueRescue|nil (readonly)

Returns the rescue clause.

Returns:

  • (Rescue|nil)

    the rescue clause.



1378
1379
1380
# File 'lib/yadriggy/ast.rb', line 1378

def rescue
  @rescue
end

Class Method Details

.tagsObject



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

def self.tags() [:brace_block, :do_block] 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.



1409
1410
1411
# File 'lib/yadriggy/ast.rb', line 1409

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

#initialize_vars(params, body) ⇒ Object



1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
# File 'lib/yadriggy/ast.rb', line 1392

def initialize_vars(params, body)
  initialize_params(params)
  if body.is_a?(Array) && body.length > 0 && body[0] == :bodystmt
    bodystmnt = body[1]
    @rescue = Rescue.make(body[2], body[3], body[4])
  else # if Ruby 2.5 or earlier
    bodystmnt = body
    @rescue = nil
  end
  @body = Exprs.make(bodystmnt)
  add_child(@body)
  add_child(@rescue)
end