Class: WhatDyaReturn::AST::Builder
- Inherits:
-
Parser::Builders::Default
- Object
- Parser::Builders::Default
- WhatDyaReturn::AST::Builder
- Defined in:
- lib/what_dya_return/ast/builder.rb
Overview
This file is based on github.com/rubocop/rubocop-ast/blob/v1.28.1/lib/rubocop/ast/builder.rb The original code is licensed under the MIT License.
Constant Summary collapse
- NODE_MAP =
{ def: DefNode, begin: BeginNode, kwbegin: BeginNode, array: ArrayNode, return: ReturnNode, if: IfNode, case: CaseNode, when: WhenNode, rescue: RescueNode, resbody: ResbodyNode, ensure: EnsureNode, while: WhileNode, until: UntilNode, for: ForNode, break: BreakNode, next: NextNode, block: BlockNode }.freeze
Instance Method Summary collapse
-
#n(type, children, source_map) ⇒ Node
NOTE: Reason why wrap with ArrayNode if the node is ‘return` or `break` and has multiple children.
Instance Method Details
#n(type, children, source_map) ⇒ Node
NOTE: Reason why wrap with ArrayNode if the node is ‘return` or `break` and has multiple children.
To treat `return 1, 2` like `return [1, 2]`.
39 40 41 42 43 |
# File 'lib/what_dya_return/ast/builder.rb', line 39 def n(type, children, source_map) children = [ArrayNode.new(:array, children)] if %i[return break].include?(type) && children.size > 1 node_klass(type).new(type, children, location: source_map) end |