Open doliveirakn opened 10 years ago
What if instead of a hash we use an array to define mappings? This way, we can iterate on that array, and check for duplicate keys. Not as clean as using a hash, and breaks the current API, but solves the problem:
config.add :actor, [
[1, 'A'],
[1, 'B']
]
Using hash its impossible to detect this. Ruby emits a warning, but I think that's no way to handle this...
x = {1=> 'A', 1=> 'B'}
warning: key 1 is duplicated and overwritten on line 3
Right now you can create collisions by doing something like
If you did something like this, all references to 'A' will become references to 'B' and that could be catastrophic. A mechanism should be added so that this is prevented at a code level.