Giter Club home page Giter Club logo

Comments (5)

rafaelfranca avatar rafaelfranca commented on August 12, 2024 1

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.

volmer avatar volmer commented on August 12, 2024

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 for is_a? or kind_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.

gmalette avatar gmalette commented on August 12, 2024

BasicObject is an instance of Class and responds to ===, the instances of BasicObject are irrelevant.

from ruby-style-guide.

volmer avatar volmer commented on August 12, 2024

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.

gmalette avatar gmalette commented on August 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.