Class: CustomCops::DefineMethod

Inherits:
RuboCop::Cop::Base
  • Object
show all
Defined in:
lib/simplycop/custom_cops/define_method.rb

Overview

This cop checks for dynamically defining methods

Examples:

#bad
Foo.define_method(:bar) { p 'bar }

#good
#create the method on the object
class Foo
   def self.bar
     puts 'bar'
   end
end

Constant Summary collapse

MSG =
'Avoid define_method.'

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



23
24
25
26
27
# File 'lib/simplycop/custom_cops/define_method.rb', line 23

def on_send(node)
  return unless defining_method?(node)

  add_offense(node.loc.selector)
end