class RuboCop::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/rubocop/cop/style/global_vars.rb, line 49 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/rubocop/cop/style/global_vars.rb, line 61 def check(node) global_var, = *node add_offense(node, location: :name) unless allowed_var?(global_var) end
on_gvar(node)
click to toggle source
# File lib/rubocop/cop/style/global_vars.rb, line 53 def on_gvar(node) check(node) end
on_gvasgn(node)
click to toggle source
# File lib/rubocop/cop/style/global_vars.rb, line 57 def on_gvasgn(node) check(node) end
user_vars()
click to toggle source
# File lib/rubocop/cop/style/global_vars.rb, line 45 def user_vars cop_config['AllowedVariables'].map(&:to_sym) end