class RubbyCop::Cop::Style::GlobalVars

This cops looks for uses of global variables. It does not report offenses for built-in global variables. Built-in global variables are allowed by default. Additionally users can allow additional variables via the AllowedVariables option.

Note that backreferences like $1, $2, etc are not global variables.

Constants

BUILT_IN_VARS

predefined global variables their English aliases www.zenspider.com/Languages/Ruby/QuickRef.html

MSG

Public Instance Methods

allowed_var?(global_var) click to toggle source
# File lib/rubbycop/cop/style/global_vars.rb, line 50
def allowed_var?(global_var)
  BUILT_IN_VARS.include?(global_var) || user_vars.include?(global_var)
end
check(node) click to toggle source
# File lib/rubbycop/cop/style/global_vars.rb, line 62
def check(node)
  global_var, = *node

  add_offense(node, :name) unless allowed_var?(global_var)
end
on_gvar(node) click to toggle source
# File lib/rubbycop/cop/style/global_vars.rb, line 54
def on_gvar(node)
  check(node)
end
on_gvasgn(node) click to toggle source
# File lib/rubbycop/cop/style/global_vars.rb, line 58
def on_gvasgn(node)
  check(node)
end
user_vars() click to toggle source
# File lib/rubbycop/cop/style/global_vars.rb, line 46
def user_vars
  cop_config['AllowedVariables'].map(&:to_sym)
end