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

TrivialAccessors check problem #308

Closed
lenntt opened this issue Jun 28, 2013 · 6 comments
Closed

TrivialAccessors check problem #308

lenntt opened this issue Jun 28, 2013 · 6 comments

Comments

@lenntt
Copy link

lenntt commented Jun 28, 2013

I have some subclass that overrides a method:

def some_method
  @variable_with_a_different_name
end

Rubocop thinks this is a TrivialAccessor offence, but I tend to disagree. What do you think? I dont think there is an easy way to refactor this into an attr_reader?

@bbatsov
Copy link
Collaborator

bbatsov commented Jun 28, 2013

This behaviour is intentional. Despite the different name this is still an attr_reader. You can always use alias_method to access the attribute via a different name.

At some point we might introduce some configuration regarding exact name matches.

@yujinakayama @jonas054 Would you share your thoughts on the subject?

@lenntt
Copy link
Author

lenntt commented Jun 28, 2013

Thanks for the fast and clear explanation. Its not what I can directly derrive from the ruby-style-guide.

What if I want to keep my @variable_with_a_different_name hidden?.
There are of course ways to implement it, but I don't think it would make my code better readable.

@bbatsov
Copy link
Collaborator

bbatsov commented Jun 28, 2013

Even now you can simply instruct RuboCop to skip the TrivialAccessors check for that particular method.

@lenntt
Copy link
Author

lenntt commented Jun 28, 2013

Thanks, that could be useful (though I strongly dislike having rubocop-specific code in my source code).

@yujinakayama
Copy link
Collaborator

Though I think TrivialAccessors is not perfect, but at least in this case, I don't think the offence is a problem.

With the provided information, I wonder why you don't use @some_method (though this is unpractical name, probably something like @some_attr) internally and just declare attr_reader :some_method.

@badal
Copy link

badal commented Jun 28, 2013

One use case may be duck-typing. You may have to provide a definition
def duck_typed_method
@another_name
end

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