Re: Proposing new warning
Dave Aronson <[email protected]>
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <CAHxKQiigbGtzuTN6CoGiZYoC3JofJUcmWogDr8tXOfxR12G-hQ@mail.gmail.com> |
On Tue, Oct 23, 2018 at 1:07 PM Hassan Schroeder <[email protected]> wrote: > I'm not sure I understand why -- *any* object can be a Hash key, not > only strings or symbols. True, but those two are *very* commonly confused, and not only by n00bz. > If I had a use case for requiring keys to be the same type I would > probably either subclass Hash or rely on a linter like RuboCop. Yeah, subclassing Hash to accept only one kind of key sprang to my mind too, as the most reliable way, and relatively easy. (Or if you don't need to use the same value both ways, just use a HashWithIndifferentAccess. Even if it's not a Rails app so that would be built in, you can import ActiveSupport, or easily rebuild the same basic functionality.) But now you've got me wondering what it would take to make Rubocop spot it. The trouble would be, just like the thermos keeping hot stuff hot and cold stuff cold, how would it know? Expecting it to parse enough of the AST to know what types are already in a hash, doesn't strike me as feasible -- it could even be undecidable. I suppose we could tag each one with a comment Rubocop understands, but that seems like overkill and a PITA. Other wild and crazy ideas? -- Dave Aronson, Software Development Consultant The T. Rex of Codosaurus, LLC (http://www.Codosaur.us) What can we help you evolve today? Unsubscribe: <mailto:[email protected]?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>