This cop makes sure that all methods use the configured style, snake_case or camelCase, for their names. Some special arrangements have to be made for operator methods.
# File lib/rubocop/cop/style/method_name.rb, line 35 def message(style) format('Use %s for methods.', style) end
# File lib/rubocop/cop/style/method_name.rb, line 19 def name_of_instance_method(def_node) expr = def_node.loc.expression match = /^def(\s+)([\w]+[!?=]?\b)/.match(expr.source) return unless match space, method_name = match.captures begin_pos = expr.begin_pos + 'def'.length + space.length Parser::Source::Range.new(expr.source_buffer, begin_pos, begin_pos + method_name.length) end
# File lib/rubocop/cop/style/method_name.rb, line 29 def name_of_singleton_method(defs_node) scope, method_name, _args, _body = *defs_node after_dot(defs_node, method_name.length, "def\s+" + Regexp.escape(scope.loc.expression.source)) end
Generated with the Darkfish Rdoc Generator 2.