Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a mechanism to help prevent collisions #9

Open
doliveirakn opened this issue Oct 21, 2014 · 1 comment
Open

Add a mechanism to help prevent collisions #9

doliveirakn opened this issue Oct 21, 2014 · 1 comment

Comments

@doliveirakn
Copy link
Contributor

Right now you can create collisions by doing something like

config.add :actor, {
  1 => 'A',
  1 => 'B'
}

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.

@fmluizao
Copy link
Contributor

fmluizao commented Apr 17, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants