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

Properly check for key presence #465

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

iGEL
Copy link
Contributor

@iGEL iGEL commented Mar 19, 2018

Hashes can have default values different from nil, see https://docs.ruby-lang.org/en/2.5.0/Hash.html#method-i-default-3D

So we must not rely on the hash returning nil for missing keys.

Hashes can have default values different from nil, see
https://docs.ruby-lang.org/en/2.5.0/Hash.html#method-i-default-3D
So we must not rely on the hash returning nil for missing keys.
@seuros
Copy link
Member

seuros commented Apr 24, 2018

But if the value is nil, then Collection.new will crash since nil don't have #each_with_index

@iGEL
Copy link
Contributor Author

iGEL commented Apr 24, 2018

That is correct, but why would the user explicitly set the collection to nil? How does this differ from setting the collection to true or the number 3, which we don't protect against either?

The usual contract of a collection with no items is, well, an empty collection. 😉

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

Successfully merging this pull request may close these issues.

None yet

2 participants