Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Fix handling of default proc values in Mash #259
referenced this pull request
Dec 29, 2014
You're right, the previous fix only handled empty arrays. Hashes are also bugged - empty or not:
I've rewritten the fix to handle empty/non-empty arrays and hashes. I also did a rebase.
Okay, I made a few more adjustments to the fix. It should now also handle hash-type accessors:
How this works: The default proc sets a key's initial value, but it's return value is also immediately returned. But Mash is converting values by default, and the object returned by the default proc is different from what is actually persisted. This is apparent if we fetch a key's value twice and inspect their object IDs:
What this updated fix does is to call the default proc first if the key has not been set, and then fetch the actual key's persisted value instead of relying on the default proc's return value.
I also got the RuboCop warning fixed. Although it looks like we're already on the threshold in terms of LoC for Mash. :(