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

I don't _agree_ with the preference expressed in the guide, but I think I understand the issue. Consider this Ruby code: #70

Closed
mulham99 opened this issue Jun 4, 2020 · 1 comment

Comments

@mulham99
Copy link

mulham99 commented Jun 4, 2020

I don't agree with the preference expressed in the guide, but I think I understand the issue. Consider this Ruby code:

class A 
  class << self 
    attr_accessor :some_attribute 
  end 
end 

class B < A 
end 

As far as I know, that's the only way to support usage like this:

A.some_attribute = :value_1 
B.some_attribute # => nil 
B.some_attribute = :value_2 
A.some_attribute # => :value_1 

I mean, using a class variable would cause it to be shared by A and B, which we don't want.

Does that sound right to you? Is there another way to implement that snippet above?

I think the same thing is true for alias, it only works for class methods inside class << self.

So, I don't agree with the preference, but I think that explains the difference, does that make sense?

Originally posted by @rmosolgo in #7 (comment)

@mulham99 mulham99 closed this as completed Jun 4, 2020
@mulham99 mulham99 reopened this Jun 4, 2020
@composerinteralia
Copy link
Member

RuboCop added a cop in 2020 that covers this: rubocop/rubocop#8381. Our style guide matches the default for this cop, and otherwise it's mostly a matter of preference.

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