Class: Unparser::AST::LocalVariableScope
- Inherits:
-
Object
- Object
- Unparser::AST::LocalVariableScope
- Includes:
- Enumerable, Unparser::Adamantium
- Defined in:
- lib/unparser/ast/local_variable_scope.rb
Overview
Calculated local variable scope for a given node
Instance Method Summary collapse
-
#first_assignment?(node) ⇒ Boolean
private
Test if local variable was first at given assignment.
-
#first_assignment_in?(left, right) ⇒ Boolean
private
Test if local variables where first assigned in body and read by conditional.
-
#initialize(node) ⇒ undefined
constructor
private
Initialize object.
-
#local_variable_defined_for_node?(node, name) ⇒ Boolean
private
Test if local variable is defined for given node.
Constructor Details
#initialize(node) ⇒ undefined
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.
Initialize object
18 19 20 21 22 23 24 |
# File 'lib/unparser/ast/local_variable_scope.rb', line 18 def initialize(node) items = [] LocalVariableScopeEnumerator.each(node) do |*scope| items << scope end @items = items end |
Instance Method Details
#first_assignment?(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 if local variable was first at given assignment
34 35 36 37 38 39 |
# File 'lib/unparser/ast/local_variable_scope.rb', line 34 def first_assignment?(node) name = node.children.first match(node) do |current, before| current.include?(name) && !before.include?(name) end end |
#first_assignment_in?(left, right) ⇒ 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 if local variables where first assigned in body and read by conditional
63 64 65 66 67 68 69 70 71 |
# File 'lib/unparser/ast/local_variable_scope.rb', line 63 def first_assignment_in?(left, right) condition_reads = AST.local_variable_reads(right) candidates = AST.local_variable_assignments(left).select do |node| condition_reads.include?(node.children.first) end candidates.any?(&public_method(:first_assignment?)) end |
#local_variable_defined_for_node?(node, name) ⇒ 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 if local variable is defined for given node
50 51 52 53 54 |
# File 'lib/unparser/ast/local_variable_scope.rb', line 50 def local_variable_defined_for_node?(node, name) match(node) do |current| current.include?(name) end end |