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.
1312 1313 1314 1315 1316 1317 1318 1319 1320 |
# File 'lib/yadriggy/ast.rb', line 1312 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.
1306 1307 1308 |
# File 'lib/yadriggy/ast.rb', line 1306 def body @body end |
#rescue ⇒ Rescue|nil (readonly)
Returns the rescue clause.
1308 1309 1310 |
# File 'lib/yadriggy/ast.rb', line 1308 def rescue @rescue end |
Class Method Details
.tags ⇒ Object
1310 |
# File 'lib/yadriggy/ast.rb', line 1310 def self.() [:brace_block, :do_block] end |
Instance Method Details
#accept(evaluator) ⇒ void
This method returns an undefined value.
A method for Visitor pattern.
1339 1340 1341 |
# File 'lib/yadriggy/ast.rb', line 1339 def accept(evaluator) evaluator.block(self) end |
#initialize_vars(params, body) ⇒ Object
1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 |
# File 'lib/yadriggy/ast.rb', line 1322 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.4 or earlier bodystmnt = body @rescue = nil end @body = Exprs.make(bodystmnt) add_child(@body) add_child(@rescue) end |