Sha256: 5d5aa6810fbf6945374faf4f92255160c23395711960db07763a25661e2401cb

Contents?: true

Size: 589 Bytes

Versions: 106

Compression:

Stored size: 589 Bytes

Contents

# frozen_string_literal: true

module CustomCops
  #  This cop checks for dynamically defining methods
  #
  # @example
  #   #bad
  #   Foo.define_method(:bar) { p 'bar }
  #
  #   #good
  #   #create the method on the object
  #   class Foo
  #      def self.bar
  #        puts 'bar'
  #      end
  #   end
  #
  class DefineMethod < RuboCop::Cop::Cop
    MSG = 'Avoid define_method.'

    def_node_matcher :defining_method?, '(send _ :define_method ...)'

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

      add_offense(node, location: :selector)
    end
  end
end

Version data entries

106 entries across 106 versions & 1 rubygems

Version Path
simplycop-2.6.0 lib/simplycop/custom_cops/define_method.rb
simplycop-2.5.1 lib/simplycop/custom_cops/define_method.rb
simplycop-2.5.0 lib/simplycop/custom_cops/define_method.rb
simplycop-2.3.3 lib/simplycop/custom_cops/define_method.rb
simplycop-2.3.2 lib/simplycop/custom_cops/define_method.rb
simplycop-2.3.1 lib/simplycop/custom_cops/define_method.rb
simplycop-2.3.0 lib/simplycop/custom_cops/define_method.rb
simplycop-2.2.0 lib/simplycop/custom_cops/define_method.rb
simplycop-2.1.4 lib/simplycop/custom_cops/define_method.rb
simplycop-2.1.3 lib/simplycop/custom_cops/define_method.rb
simplycop-2.1.2 lib/simplycop/custom_cops/define_method.rb
simplycop-2.1.0 lib/simplycop/custom_cops/define_method.rb
simplycop-2.0.1 lib/simplycop/custom_cops/define_method.rb
simplycop-2.0.0 lib/simplycop/custom_cops/define_method.rb
simplycop-1.19.3 lib/simplycop/custom_cops/define_method.rb
simplycop-1.19.2 lib/simplycop/custom_cops/define_method.rb
simplycop-1.19.1 lib/simplycop/custom_cops/define_method.rb
simplycop-1.19.0 lib/simplycop/custom_cops/define_method.rb
simplycop-1.17.0 lib/simplycop/custom_cops/define_method.rb
simplycop-1.16.6 lib/simplycop/custom_cops/define_method.rb