Sha256: cd14b920580d76d8f509978682ab6d1e1e5d403b1d1a4c15424e8b8e19262f41

Contents?: true

Size: 582 Bytes

Versions: 14

Compression:

Stored size: 582 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::Base
    MSG = 'Avoid define_method.'

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

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

      add_offense(node.loc.selector)
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
simplycop-2.13.2 lib/simplycop/custom_cops/define_method.rb
simplycop-2.13.1 lib/simplycop/custom_cops/define_method.rb
simplycop-2.13.0 lib/simplycop/custom_cops/define_method.rb
simplycop-2.12.1 lib/simplycop/custom_cops/define_method.rb
simplycop-2.12.0 lib/simplycop/custom_cops/define_method.rb
simplycop-2.11.1 lib/simplycop/custom_cops/define_method.rb
simplycop-2.11.0 lib/simplycop/custom_cops/define_method.rb
simplycop-2.10.0 lib/simplycop/custom_cops/define_method.rb
simplycop-2.9.1 lib/simplycop/custom_cops/define_method.rb
simplycop-2.9.0 lib/simplycop/custom_cops/define_method.rb
simplycop-2.8.0 lib/simplycop/custom_cops/define_method.rb
simplycop-2.7.2 lib/simplycop/custom_cops/define_method.rb
simplycop-2.7.1 lib/simplycop/custom_cops/define_method.rb
simplycop-2.7.0 lib/simplycop/custom_cops/define_method.rb