Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

self.method_missing on require respond_to_missing as instance method instead of class method #3358

Closed
Rataah opened this issue Aug 1, 2016 · 1 comment

Comments

@Rataah
Copy link

Rataah commented Aug 1, 2016

Hi,

For some reasons, I defined the method_missing as a class method.
The corresponding cop rejects my code because respond_to_missing? is missing.
I assume this method should be a class method too but this doesn't work. The cop accepts only if I declare an instance method.

Here is an example:

# Rubocop method_missing issue
# this should be OK
class GoodExample
  def self.some_method
  end

  def self.method_missing(method, *args)
    super
  end

  def self.respond_to_missing?
    true
  end
end

# Rubocop method_missing issue
# this works but not as we expect
class BadExample
  def self.some_method
  end

  def self.method_missing(method, *args)
    super
  end

  def respond_to_missing?
    true
  end
end
Inspecting 1 file
C

Offenses:

example.rb:7:3: C: When using method_missing, define respond_to_missing?.
  def self.method_missing(method, *args) ...
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected

Version used: 0.42.0

Insti added a commit to Insti/rubycritic that referenced this issue Aug 4, 2016
Add self.respond_to_missing? method to Config module.

But...

Due to this rubocop issue:
rubocop/rubocop#3358
an offense is still detected.
Drenmi added a commit to Drenmi/rubocop that referenced this issue Aug 5, 2016
This cop would check for an instance method named `#respond_to_missing?`
even if `#method_missing` was implemented as a class method.

This fixes that by ensuring that the cop looks in the same scope.
@bbatsov bbatsov closed this as completed in 0ea58bf Aug 6, 2016
soutaro added a commit to soutaro/rubocop that referenced this issue Aug 7, 2016
If last `rescue` is without parameter, location calculation of offense raises an `NoMethodError`.

This fixes that by using location of `rescue` keyword in that case.
bbatsov pushed a commit that referenced this issue Aug 7, 2016
If last `rescue` is without parameter, location calculation of offense raises an `NoMethodError`.

This fixes that by using location of `rescue` keyword in that case.
@kke
Copy link

kke commented Sep 9, 2016

Pushing to rubygems anytime soon?

Neodelf pushed a commit to Neodelf/rubocop that referenced this issue Oct 15, 2016
rubocop#3368)

This cop would check for an instance method named `#respond_to_missing?`
even if `#method_missing` was implemented as a class method.

This fixes that by ensuring that the cop looks in the same scope.
Neodelf pushed a commit to Neodelf/rubocop that referenced this issue Oct 15, 2016
If last `rescue` is without parameter, location calculation of offense raises an `NoMethodError`.

This fixes that by using location of `rescue` keyword in that case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants