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

Delegate cop should ignore class delegation #1509

Closed
mockdeep opened this issue Dec 18, 2014 · 6 comments
Closed

Delegate cop should ignore class delegation #1509

mockdeep opened this issue Dec 18, 2014 · 6 comments

Comments

@mockdeep
Copy link
Contributor

We have code like this:

class MyClass

  def self.do_something(args)
    new.do_something(args)
  end

  def do_something(args)
    ...
  end
end

And we get a delegate violation: Rails/Delegate: Use delegate to define delegations..

@mockdeep mockdeep changed the title Delegate cop should ignore class to instance delegation Delegate cop should ignore class delegation Dec 18, 2014
@ivanoblomov
Copy link

+1

@ghost
Copy link

ghost commented Jan 20, 2015

+1, or is there a better practice than using class delegation?

@walterhorstman
Copy link

I've just stumbled over the same issue when I write the following code. If the code is wrong, please tell me how to fix it. Else, it might be a new bug, or this one should be reopened.

def self.[](code)
  indexed[code]
end

def self.indexed
  all.index_by(&:code)
end

My goal is to be able to write things like MyClass[:something] instead of MyClass.indexed[:something].

@bbatsov
Copy link
Collaborator

bbatsov commented Jan 30, 2015

This is fixed on master.

@walterhorstman
Copy link

Are you sure? I've changed the definition in the Gemfile to use the Github repo and it still occurs.

@bbatsov
Copy link
Collaborator

bbatsov commented Jan 30, 2015

I'm sure we're no longer processing class methods, so I cannot imagine how this can still happen.

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