You are not storing waldo where you think you are storing it. On first access @store[:foo] is already initialized, so it does away with your waldo assignment, then on second and third access you are populating it. my_hash[:baz] is @store[:foo][:baz].
I don’t believe that’s correct. And testing it out by replacing the HashWithIndifferentAccess with a regular Ruby Hash gives the expected result, so it’s definitely different behavior than expected.
That being said, I just tested it on Rails 4.2.3 and it works as expected, so I’m not sure why Yves is seeing a different result.
to convert incoming plain Hash objects into HWIA. So the object that eventually is stored in `@store[:foo]` is NOT the one that was passed to the assignment operator.
Note that `first_time` and `second_time` don’t have matching `inspect` results.
Assignment operators *always* return the value passed on the right-hand side, regardless of what the underlying `=` method returns. This means that in cases where the object doesn’t require conversion (coalwater’s modification from your Gist) the object returned from `||=` DOES match, and Waldo is found.
Not sure if there’s a fix for this - the converting-on-= behavior is something many applications are likely to depend on, and the behavior of assignment operators is a core Ruby issue.
The = operator should still return whatever it sets, though, which would mean the two different accesses should return the same thing. And I believe this is the case currently. To not do so would be a legitimate bug.