intridea/hashie — pull request #240 by bartoszkopinski (2014-11-27 04:11:13+00:00)
Title: Clash: cannot nest twice even when key is Clash class

Hello,

In the example found in README:

https://github.com/intridea/hashie#clash

The suggestion to access one of the nested hashes is by using bang methods:

```ruby
c = Hashie::Clash.new
c.where!.nested(10)._end!
# => {:where=>{:nested=>10}}
```

However, a second attempt to do the same results in `ChainError` exception:

```ruby
c = Hashie::Clash.new
c.where!.nested(10)._end!
c.where!.another(10)._end!
Hashie::Clash::ChainError: Tried to chain into a non-hash key.
```

Of course this is a naive example, as the issue trying to solve is merge nested elements:

```ruby
c = Hashie::Clash.new
c.where(location: { near: [1, 2] })
# => {:where=>{:location=>{:near=>[1, 2]}}}
c.where(location: { distance: "100mi" })
# => {:where=>{:location=>{:distance=>"100mi"}}}
```

There is no way, without using the nested (bang) methods to workaround this limitation.

Looking at the logic of the code:

https://github.com/intridea/hashie/blob/59069f13ea067a319584a56674cc02de887b999f/lib/hashie/clash.rb#L73-L76

Seems that one scenario is missing, which is the case when `self[key]` is already a `Clash` instance.

Wanted to confirm if is the desired behavior, there are alternatives or a pull request might be in order :grin:

Thank you!