123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, Branchable
Inherits: Object
Defined in: lib/rubocop/cop/variable_force/reference.rb

Overview

This class represents each reference of a variable.

Constant Summary

Class Method Summary

Instance Attribute Summary

  • #explicit? ⇒ Boolean readonly Internal use only

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

  • #node readonly Internal use only
  • #scope readonly Internal use only

Instance Method Summary

Constructor Details

.new(node, scope) ⇒ Reference

[ GitHub ]

  
# 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

#explicit?Boolean (readonly)

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.

[ GitHub ]

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

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

#node (readonly)

[ GitHub ]

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

attr_reader :node, :scope

#scope (readonly)

[ GitHub ]

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

attr_reader :node, :scope