Parent

Files

Class/Module Index [+]

Quicksearch

RuboCop::Cop::VariableForce::Scope

A Scope represents a context of local variable visibility. This is a place where local variables belong to. A scope instance holds a scope node and variable entries.

Attributes

node[R]
variables[R]

Public Class Methods

new(node) click to toggle source
# File lib/rubocop/cop/variable_force/scope.rb, line 11
def initialize(node)
  # Accept begin node for top level scope.
  unless SCOPE_TYPES.include?(node.type) || node.type == :begin
    fail ArgumentError,
         "Node type must be any of #{SCOPE_TYPES}, "                   "passed #{node.type}"
  end
  @node = node
  @variables = {}
end

Public Instance Methods

==(other) click to toggle source
# File lib/rubocop/cop/variable_force/scope.rb, line 22
def ==(other)
  @node.equal?(other.node)
end
ancestors_of_node(target_node) click to toggle source
# File lib/rubocop/cop/variable_force/scope.rb, line 45
def ancestors_of_node(target_node)
  ASTScanner.scan(@node) do |scanning_node, ancestor_nodes|
    return ancestor_nodes[1..-1] if scanning_node.equal?(target_node)
  end

  fail "Node #{target_node} is not found in scope #{@node}"
end
body_node() click to toggle source
# File lib/rubocop/cop/variable_force/scope.rb, line 34
def body_node
  child_index = case @node.type
                when :top_level           then 0
                when :module, :sclass     then 1
                when :def, :class, :block then 2
                when :defs                then 3
                end

  @node.children[child_index]
end
name() click to toggle source
# File lib/rubocop/cop/variable_force/scope.rb, line 26
def name
  case @node.type
  when :def  then @node.children[0]
  when :defs then @node.children[1]
  else nil # TODO
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.