class RuboCop::Cop::Style::MethodMissing

This cop checks for the presence of `method_missing` without also defining `respond_to_missing?` and falling back on `super`.

@example

#bad
def method_missing(...)
  ...
end

#good
def respond_to_missing?(...)
  ...
end

def method_missing(...)
  ...
  super
end

Constants

MSG

Public Instance Methods

on_def(node) click to toggle source
# File lib/rubocop/cop/style/method_missing.rb, line 26
def on_def(node)
  return unless node.method?(:method_missing)

  check(node)
end
Also aliased as: on_defs
on_defs(node)
Alias for: on_def

Private Instance Methods

calls_super?(node) click to toggle source
# File lib/rubocop/cop/style/method_missing.rb, line 55
def calls_super?(node)
  node.descendants.any?(&:zsuper_type?)
end
check(node) click to toggle source
# File lib/rubocop/cop/style/method_missing.rb, line 35
def check(node)
  return if calls_super?(node) && implements_respond_to_missing?(node)

  add_offense(node)
end
implements_respond_to_missing?(node) click to toggle source
# File lib/rubocop/cop/style/method_missing.rb, line 59
def implements_respond_to_missing?(node)
  node.parent.each_child_node(node.type).any? do |sibling|
    sibling.method?(:respond_to_missing?)
  end
end
message(node) click to toggle source
# File lib/rubocop/cop/style/method_missing.rb, line 41
def message(node)
  instructions = []

  unless implements_respond_to_missing?(node)
    instructions << 'define `respond_to_missing?`'.freeze
  end

  unless calls_super?(node)
    instructions << 'fall back on `super`'.freeze
  end

  format(MSG, instructions.join(' and '))
end