Class: Yadriggy::Block
- Inherits:
-
Parameters
- Object
- ASTnode
- Parameters
- Yadriggy::Block
- Defined in:
- lib/yadriggy/ast.rb
Overview
Block.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#body ⇒ ASTnode
readonly
The body.
-
#rescue ⇒ Rescue|nil
readonly
The rescue clause.
Attributes inherited from Parameters
#block_param, #keywords, #optionals, #params, #params_after_rest, #rest_of_keywords, #rest_of_params
Attributes inherited from ASTnode
Class Method Summary collapse
Instance Method Summary collapse
-
#accept(evaluator) ⇒ void
A method for Visitor pattern.
-
#initialize(sexp) ⇒ Block
constructor
A new instance of Block.
- #initialize_vars(params, body) ⇒ Object
Methods inherited from Parameters
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
#body ⇒ ASTnode (readonly)
Returns the body.
1376 1377 1378 |
# File 'lib/yadriggy/ast.rb', line 1376 def body @body end |
#rescue ⇒ Rescue|nil (readonly)
Returns the rescue clause.
1378 1379 1380 |
# File 'lib/yadriggy/ast.rb', line 1378 def rescue @rescue end |
Class Method Details
.tags ⇒ Object
1380 |
# File 'lib/yadriggy/ast.rb', line 1380 def self.() [:brace_block, :do_block] end |
Instance Method Details
#accept(evaluator) ⇒ void
This method returns an undefined value.
A method for 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 |