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

Lint/UselessAccessModifier thinks a private attr_writer is useless #2517

Closed
maxjacobson opened this issue Dec 19, 2015 · 4 comments
Closed

Comments

@maxjacobson
Copy link
Contributor

Consider this code:

class DogWalker
  attr_reader :dogs

  def initialize(*dogs)
    @dogs = dogs
  end

  def add_dog(dog)
    self.dogs = dogs + [dog]
  end

  private

  attr_writer :dogs
end

walker = DogWalker.new("milo", "lola")
walker.add_dog("Bean") # (uses the private attr_writer)
walker.dogs = [1, 2, 3] # (tries to use the attr_writer but fails because it's private)

The attr_writer :dogs there is private, but this generates a Lint/UselessAccessModifier offense even though sometimes it is useful to define a private setter (not sure how useful this particular example is 😄)

@maxjacobson
Copy link
Contributor Author

This is on the latest master (0195325) -- I'm trying it out on some of our code to see what's new 😄

@alexdowad
Copy link
Contributor

Good point. Just fixing this.

@alexdowad
Copy link
Contributor

I had attr, attr_reader, and attr_accessor covered, but not attr_writer.

@alexdowad
Copy link
Contributor

OK, just pushed a fix here.

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