Module: Unparser::AST
- Defined in:
- lib/unparser/ast.rb,
lib/unparser/ast/local_variable_scope.rb
Overview
Namespace for AST processing tools :reek:TooManyConstants
Defined Under Namespace
Classes: Enumerator, LocalVariableScope, LocalVariableScopeEnumerator, Walker
Constant Summary collapse
- FIRST_CHILD =
->(node) { node.children.first }.freeze
- TAUTOLOGY =
->(_node) { true }.freeze
- RESET_NODES =
i[module class sclass def defs].freeze
- INHERIT_NODES =
[:block].freeze
- CLOSE_NODES =
(RESET_NODES + INHERIT_NODES).freeze
- ASSIGN_NODES =
Nodes that assign a local variable
i[ arg kwarg kwoptarg lvasgn optarg procarg0 restarg ].to_set.freeze
Class Method Summary collapse
-
.local_variable_assignments(node) ⇒ Set<Symbol>
private
Return local variables that get assigned in scope.
-
.local_variable_reads(node) ⇒ Set<Symbol>
private
Return local variables read.
-
.not_close_scope?(node) ⇒ Boolean
private
Test for local variable inherited scope reset.
-
.not_reset_scope?(node) ⇒ Boolean
private
Test for local variable scope reset.
Class Method Details
.local_variable_assignments(node) ⇒ Set<Symbol>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return local variables that get assigned in scope
59 60 61 62 63 64 |
# File 'lib/unparser/ast.rb', line 59 def self.local_variable_assignments(node) Enumerator.new( node, method(:not_reset_scope?) ).types(ASSIGN_NODES) end |
.local_variable_reads(node) ⇒ Set<Symbol>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return local variables read
74 75 76 77 78 79 |
# File 'lib/unparser/ast.rb', line 74 def self.local_variable_reads(node) Enumerator.new( node, method(:not_close_scope?) ).type(:lvar).map(&FIRST_CHILD).to_set end |
.not_close_scope?(node) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Test for local variable inherited scope reset
35 36 37 |
# File 'lib/unparser/ast.rb', line 35 def self.not_close_scope?(node) !CLOSE_NODES.include?(node.type) end |
.not_reset_scope?(node) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Test for local variable scope reset
47 48 49 |
# File 'lib/unparser/ast.rb', line 47 def self.not_reset_scope?(node) !RESET_NODES.include?(node.type) end |