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

Raise on non-existent key #171

Closed
Fryguy opened this issue May 5, 2017 · 5 comments · Fixed by #182
Closed

Raise on non-existent key #171

Fryguy opened this issue May 5, 2017 · 5 comments · Fixed by #182
Milestone

Comments

@Fryguy
Copy link
Member

Fryguy commented May 5, 2017

Another useful feature might be an option that instead of returning nil on a non-existent key, would instead raise an exception. I feel this could be similar to Hash#fetch.

cc @cben

@aspirewit
Copy link

@Fryguy You can use the validation, more details

@jcoyne
Copy link

jcoyne commented Sep 15, 2017

@aspirewit I'm not sure validations would work in every case. For example I have a configuration like this:

app:
  driver:  'foxtrot'
  foxtrot:
   beats: 4
  waltz:
    beats: 3

Now I might want to resolve:

Settings.app.fetch(Settings.driver)

@amyin
Copy link

amyin commented Oct 11, 2017

+1 I would also love run-time errors on non-existent keys, something like a ENV.fetch

@cben
Copy link

cben commented Oct 12, 2017

https://github.com/obrok/closed_struct may be useful for implementing this.

EDIT: it's also immutable, which is not so desired...

@pkuczynski
Copy link
Member

Interesting, but I have no time to work on this at the moment...

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

Successfully merging a pull request may close this issue.

6 participants