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.16.5 lib/simplycop/custom_cops/define_method.rb
simplycop-1.16.4 lib/simplycop/custom_cops/define_method.rb
simplycop-1.16.3 lib/simplycop/custom_cops/define_method.rb
simplycop-1.16.2 lib/simplycop/custom_cops/define_method.rb
simplycop-1.16.1 lib/simplycop/custom_cops/define_method.rb
simplycop-1.16.0 lib/simplycop/custom_cops/define_method.rb
simplycop-1.15.1 lib/simplycop/custom_cops/define_method.rb
simplycop-1.15.0 lib/simplycop/custom_cops/define_method.rb
simplycop-1.14.18 lib/simplycop/custom_cops/define_method.rb
simplycop-1.14.17 lib/simplycop/custom_cops/define_method.rb
simplycop-1.14.16 lib/simplycop/custom_cops/define_method.rb
simplycop-1.14.15 lib/simplycop/custom_cops/define_method.rb
simplycop-1.14.14 lib/simplycop/custom_cops/define_method.rb
simplycop-1.14.13 lib/simplycop/custom_cops/define_method.rb
simplycop-1.14.12 lib/simplycop/custom_cops/define_method.rb
simplycop-1.14.11 lib/simplycop/custom_cops/define_method.rb
simplycop-1.14.10 lib/simplycop/custom_cops/define_method.rb
simplycop-1.14.9 lib/simplycop/custom_cops/define_method.rb
simplycop-1.14.8 lib/simplycop/custom_cops/define_method.rb
simplycop-1.14.7 lib/simplycop/custom_cops/define_method.rb