Class: Rubocop::Cop::VariableInspector::VariableEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/cop/variable_inspector.rb

Overview

A VariableEntry represents existance of a local variable. This holds a variable declaration node, and some states of the variable.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, name = nil) ⇒ VariableEntry

Returns a new instance of VariableEntry.



28
29
30
31
32
33
34
35
36
37
# File 'lib/rubocop/cop/variable_inspector.rb', line 28

def initialize(node, name = nil)
  unless VARIABLE_DECLARATION_TYPES.include?(node.type)
    fail ArgumentError,
         "Node type must be any of #{VARIABLE_DECLARATION_TYPES}, " +
         "passed #{node.type}"
  end
  @node = node
  @name = name.to_sym if name
  @used = false
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



24
25
26
# File 'lib/rubocop/cop/variable_inspector.rb', line 24

def node
  @node
end

#usedObject Also known as: used?

Returns the value of attribute used.



25
26
27
# File 'lib/rubocop/cop/variable_inspector.rb', line 25

def used
  @used
end

Instance Method Details

#nameObject



39
40
41
# File 'lib/rubocop/cop/variable_inspector.rb', line 39

def name
  @name || @node.children.first
end