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

False-Positive in Lint/DuplicateMethods for dynamic classes #2726

Closed
code-later opened this issue Jan 27, 2016 · 5 comments
Closed

False-Positive in Lint/DuplicateMethods for dynamic classes #2726

code-later opened this issue Jan 27, 2016 · 5 comments

Comments

@code-later
Copy link

I just updated from 0.35.1 to 0.36.0 and received an error for Lint/DuplicateMethods in a code similar to this:

class Human
  def initialize(attribute = {})
    @attributes = attributes
  end

  def spawn_robot(type)
    type = Class.new do
      def initialize(attributes = {})
        @attributes = attributes
      end
    end
  end
end

Running rubocop on this file will give the following error:

sandbox/rubocop_test.rb:8:7: W: Lint/DuplicateMethods: Method Human#initialize is defined at both /srv/nfs/fejo-dk/fejo-next/sandbox/rubocop_test.rb:2 and /srv/nfs/fejo-dk/fejo-next/sandbox/rubocop_test.rb:8.
      def initialize(attributes = {})
      ^^^

I think this was introduced by the improvements in 1f9c639. I'm well aware that we can argue about the code itself but I don't think this should be a Lint/DuplicateMethods violation since they are both valid.

I'm not sure how to fix this thus I'm just reporting ;-)

@bbatsov
Copy link
Collaborator

bbatsov commented Jan 31, 2016

This was fixed on master.

@bbatsov bbatsov closed this as completed Jan 31, 2016
@bbatsov bbatsov reopened this Jan 31, 2016
@bbatsov
Copy link
Collaborator

bbatsov commented Jan 31, 2016

My bad - I was thinking of a similar problem #2707

@alexdowad
Copy link
Contributor

This is fixed in my open PR.

@alexdowad
Copy link
Contributor

This is fixed on master now.

@jonas054
Copy link
Collaborator

Confirmed. The fix was released in 0.37.1.

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

4 participants