Class: RuboCop::Cop::VariableForce::Reference Private

Inherits:
Object
  • Object
show all
Includes:
Branchable
Defined in:
lib/rubocop/cop/variable_force/reference.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

This class represents each reference of a variable.

Constant Summary collapse

VARIABLE_REFERENCE_TYPES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

(
  [VARIABLE_REFERENCE_TYPE] + OPERATOR_ASSIGNMENT_TYPES + [ZERO_ARITY_SUPER_TYPE, SEND_TYPE]
).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Branchable

#branch, #run_exclusively_with?

Constructor Details

#initialize(node, scope) ⇒ Reference

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.

Returns a new instance of Reference.



16
17
18
19
20
21
22
23
24
25
# File 'lib/rubocop/cop/variable_force/reference.rb', line 16

def initialize(node, scope)
  unless VARIABLE_REFERENCE_TYPES.include?(node.type)
    raise ArgumentError,
          "Node type must be any of #{VARIABLE_REFERENCE_TYPES}, " \
          "passed #{node.type}"
  end

  @node = node
  @scope = scope
end

Instance Attribute Details

#nodeObject (readonly)

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.



14
15
16
# File 'lib/rubocop/cop/variable_force/reference.rb', line 14

def node
  @node
end

#scopeObject (readonly)

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.



14
15
16
# File 'lib/rubocop/cop/variable_force/reference.rb', line 14

def scope
  @scope
end

Instance Method Details

#explicit?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.

There’s an implicit variable reference by the zero-arity ‘super`:

def some_method(foo)
  super
end

Another case is ‘binding`:

def some_method(foo)
  do_something(binding)
end

In these cases, the variable ‘foo` is not explicitly referenced, but it can be considered used implicitly by the `super` or `binding`.

Returns:

  • (Boolean)


41
42
43
# File 'lib/rubocop/cop/variable_force/reference.rb', line 41

def explicit?
  ![ZERO_ARITY_SUPER_TYPE, SEND_TYPE].include?(@node.type)
end