Class: Solargraph::Pin::LocalVariable
- Inherits:
-
BaseVariable
- Object
- Base
- BaseVariable
- Solargraph::Pin::LocalVariable
- Defined in:
- lib/solargraph/pin/local_variable.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(source, node, namespace, ancestors) ⇒ LocalVariable
constructor
A new instance of LocalVariable.
- #visible_from?(node) ⇒ Boolean
Methods inherited from BaseVariable
#kind, #name, #return_type, #signature
Methods included from NodeMethods
#const_from, #infer_literal_node_type, #pack_name, #resolve_node_signature, #unpack_name
Methods inherited from Base
#docstring, #filename, #kind, #location, #name, #parameters, #path, #return_type, #signature, #value
Constructor Details
#initialize(source, node, namespace, ancestors) ⇒ LocalVariable
Returns a new instance of LocalVariable.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/solargraph/pin/local_variable.rb', line 4 def initialize source, node, namespace, ancestors super(source, node, namespace) @tree = [] ancestors.each do |parent| if [:block, :def, :defs, :class, :module, :source].include? parent.type @tree.push parent break unless parent.type == :block end end end |
Instance Method Details
#visible_from?(node) ⇒ Boolean
15 16 17 18 19 20 21 22 |
# File 'lib/solargraph/pin/local_variable.rb', line 15 def visible_from? node parents = [node] + (source.tree_for(node) || []) parents.each do |p| return true if @tree[0] == p return false if [:def, :defs, :class, :module].include?(p.type) end false end |