Parent

Files

Class/Module Index [+]

Quicksearch

RuboCop::Cop::Style::VariableName

This cop makes sure that all variables use the configured style, snake_case or camelCase, for their names.

Public Instance Methods

message(style) click to toggle source
# File lib/rubocop/cop/style/variable_name.rb, line 37
def message(style)
  format('Use %s for variables.', style)
end
name_of_setter(send_node) click to toggle source
# File lib/rubocop/cop/style/variable_name.rb, line 29
def name_of_setter(send_node)
  receiver, method_name = *send_node
  return unless receiver && receiver.type == :self
  return unless method_name.to_s.end_with?('=')
  after_dot(send_node, method_name.length - '='.length,
            Regexp.escape(receiver.loc.expression.source))
end
name_of_variable(vasgn_node) click to toggle source
# File lib/rubocop/cop/style/variable_name.rb, line 22
def name_of_variable(vasgn_node)
  expr = vasgn_node.loc.expression
  name = vasgn_node.children.first
  Parser::Source::Range.new(expr.source_buffer, expr.begin_pos,
                            expr.begin_pos + name.length)
end
on_ivasgn(node) click to toggle source
# File lib/rubocop/cop/style/variable_name.rb, line 14
def on_ivasgn(node)
  check(node, name_of_variable(node))
end
on_lvasgn(node) click to toggle source
# File lib/rubocop/cop/style/variable_name.rb, line 10
def on_lvasgn(node)
  check(node, name_of_variable(node))
end
on_send(node) click to toggle source
# File lib/rubocop/cop/style/variable_name.rb, line 18
def on_send(node)
  check(node, name_of_setter(node))
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.