cells icon indicating copy to clipboard operation
cells copied to clipboard

Properly check for key presence

Open iGEL opened this issue 7 years ago • 2 comments

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.

iGEL avatar Mar 19 '18 09:03 iGEL

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

seuros avatar Apr 24 '18 20:04 seuros

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. :wink:

iGEL avatar Apr 24 '18 21:04 iGEL