rails/rails — pull request #3811 by zetter (2011-11-30 15:47:20+00:00)
Title: Fix lookup on HashWithIndifferentAccess for array values.

Currently HashWithIndifferentAccess has some odd behaviour that differs from Hash.

**The problem:**
Accessing a HashWithIndifferentAccess does not return the the same object that is stored in the hash (i.e. equal?) causing unexpected results:

```ruby
hash = HashWithIndifferentAccess.new {|h, k| h[k] = []}
hash[:a] << 1 # => [1]
hash[:a] # => [], expected [1]
```

**The cause:**
When a block is provided to generate default values the generated values are duped if they are arrays. The duped value is stored in the hash but the original value is returned when the hash is accessed.

**My fix:**
The duping is there for allowing frozen arrays containing hashes to be modified. My fix restricts the duping to this case. Note that if default function generates a frozen array an error will be raised on assignment before and after my patch.