lib/rubocop/cop/class_methods.rb in rubocop-0.7.2 vs lib/rubocop/cop/class_methods.rb in rubocop-0.8.0

- old
+ new

@@ -1,20 +1,15 @@ # encoding: utf-8 module Rubocop module Cop class ClassMethods < Cop - ERROR_MESSAGE = 'Prefer self over class/module for class/module methods.' + MSG = 'Prefer self over class/module for class/module methods.' - def inspect(file, source, tokens, sexp) - # defs nodes correspond to class & module methods - each(:defs, sexp) do |s| - if s[1][0] == :var_ref && s[1][1][0] == :@const - add_offence(:convention, - s[1][1][2].lineno, - ERROR_MESSAGE) - end - end + def on_defs(node) + definee, _name, _args, _body = *node + + add_offence(:convention, node.loc.line, MSG) if definee.type == :const end end end end