dry-struct icon indicating copy to clipboard operation
dry-struct copied to clipboard

Fixes behavior of `[]` method for optional key

Open ivleonov opened this issue 2 years ago • 0 comments

It fixes #171

Few notes about this fix:

  • The assumption here is that @attributes are already validated, so no need to go to schema and check if given key is actually optional
  • Another idea here is to merge missing optional keys in @attributes variable at the moment of creating object to make sure that behavior is consistent across access methods, hash syntax ([]) and methods attributes, to_h and to_hash. Currently attributes, to_h and to_hash methods don't not return missing keys. But I'm not sure if it's reasonable behavior change (maybe someone relies on current behavior). Pls let me know if you feel so and I will extend this PR (or will open another one)

ivleonov avatar Nov 29 '21 08:11 ivleonov