Comments (5)
I'm positive to this proposal. I had this problem a few times already.
About the tangent, I think we should evaluate case by case. The Rails/DynamicFinder
which is not part of the styleguide is fine to disable in the app I know we are using it because that app uses sorbet and those dynamic methods are not going to be in the rbis. I'm not sure that will be the case of all other rules that have different semantics.
from ruby-style-guide.
If I understood correctly, the proposition to not discourage ===
is because it is a better way to check hierarchy membership than is_a?
or kind_of?
. And the reason why it is better is because instances of BasicObject
don't respond to is_a?
or kind_of?
but it does respond to ===
. I see a few problems with that:
- AFAIK instances of
BasicObject
don't respond to===
either. - In Objects,
===
is not a substitute foris_a?
orkind_of?
. The former is intended to be used for case statements while the latter is the actual method to check for superclasses.
obj === other → true or false
Case Equality – For class Object, effectively the same as calling #==, but typically overridden by descendants to provide meaningful semantics in case statements.
is_a?(class) → true or false
Returns true if class is the class of obj, or if class is one of the superclasses of obj or modules included in obj.
The reason why we discourage usage of ===
is because it is supposed to be called implicitly on case statements and not to be used for hierarchy checks.
from ruby-style-guide.
BasicObject
is an instance of Class
and responds to ===
, the instances of BasicObject
are irrelevant.
from ruby-style-guide.
BasicObject is an instance of Class and responds to ===, the instances of BasicObject are irrelevant.
So if the point here is about BasicObject
itself and not its instances then it also responds to is_a?
and kind_of?
.
from ruby-style-guide.
I don't understand what you mean here ^.
To do the "typechecking" you don't call instance === class
, you call class === instance
. The fact that instances don't have ===
is irrelevant. The fact that instances don't have is_a?
is very relevant.
from ruby-style-guide.
Related Issues (20)
- Should we expose our style guide as a gem? HOT 3
- Missing Creative Commons attribution
- Add a Table of Contents
- Add anchors to each rule
- Add more good vs bad examples
- Include reasoning in some rules
- Layout/LineLength obsolete parameter `IgnoredPatterns`
- Style/HashSyntax EnforcedShorthandSyntax setting HOT 1
- Gemspec/DateAssignment cop has been removed. HOT 1
- Recommendation on Style/ArrayIntersect? HOT 2
- Autoformat issues with v2.11.1 HOT 3
- Cut a release to eliminate rubocop 1.4 warning? HOT 2
- Move to make Policial fails a hard fail HOT 2
- Suggestion: enforce trailing commas in literals HOT 30
- Consider disabling `Style/InvertibleUnlessCondition`? HOT 3
- Consider re-evaluating Style/ModuleFunction: extend_self HOT 1
- Style guide style improvements HOT 6
- disable Style/ClassAndModuleChildren cop for tests HOT 4
- Time (and Date) doesn't always have equivalents of DateTime methods HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ruby-style-guide.