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
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?
On Tue, Oct 23, 2018 at 1:07 PM Hassan Schroeder <email@example.com> wrote:
Dave Aronson, Software Development Consultant
The T. Rex of Codosaurus, LLC
What can we help you evolve today?