Merge with symbol problem


#1

Hi,

It’s a little bit annoying to me, I can’t understand the following:

If I merge a value to the params hash with:

params => params.merge :value => new_value

the params[:value] doesn’t change, but if I use string instead of a
symbol like:

params => params.merge “value” => new_value

it works.

Somebody plz tell me why…

Abbath


#2

I believe that :value and “value” are complety different keys. One is
a string, the other is a symbol.


#3

Ok, You would be right if the params object had been a Hash. But - as
I know - it’s a HashWithIndifferentAccess object in which the symbol
and the string key should be the same.

I believe that :value and “value” are complety different keys. One is
a string, the other is a symbol.


#4

A bit late to the party, but I filed a bug on this some while ago. It’s
still in the queue, AFAIK.

In the mean while, you can work around it quite simply:

class HashWithIndifferentAccess
def merge(hash)
self.dup.update(hash)
end
end