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-1.9.4 lib/simplycop/custom_cops/define_method.rb
simplycop-1.9.3 lib/simplycop/custom_cops/define_method.rb
simplycop-1.9.2 lib/simplycop/custom_cops/define_method.rb
simplycop-1.9.1 lib/simplycop/custom_cops/define_method.rb
simplycop-1.9.0 lib/simplycop/custom_cops/define_method.rb
simplycop-1.8.1 lib/simplycop/custom_cops/define_method.rb
simplycop-1.8.0 lib/simplycop/custom_cops/define_method.rb
simplycop-1.7.5 lib/simplycop/custom_cops/define_method.rb
simplycop-1.7.4 lib/simplycop/custom_cops/define_method.rb
simplycop-1.7.3 lib/simplycop/custom_cops/define_method.rb
simplycop-1.7.2 lib/simplycop/custom_cops/define_method.rb
simplycop-1.7.1 lib/simplycop/custom_cops/define_method.rb
simplycop-1.7.0 lib/simplycop/custom_cops/define_method.rb
simplycop-1.6.4 lib/simplycop/custom_cops/define_method.rb
simplycop-1.6.3 lib/simplycop/custom_cops/define_method.rb
simplycop-1.6.2 lib/simplycop/custom_cops/define_method.rb
simplycop-1.6.1 lib/simplycop/custom_cops/define_method.rb
simplycop-1.6.0 lib/simplycop/custom_cops/define_method.rb
simplycop-1.5.0 lib/simplycop/custom_cops/define_method.rb
simplycop-1.4.2 lib/simplycop/custom_cops/define_method.rb