Forum: Ruby on Rails merge with symbol problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Abbath (Guest)
on 2006-03-02 22:14
(Received via mailing list)
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
Nithin R. (Guest)
on 2006-03-02 22:28
(Received via mailing list)
I believe that :value and "value" are complety different keys. One is
a string, the other is a symbol.
Abbath (Guest)
on 2006-03-07 23:24
(Received via mailing list)
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.
Kenneth Miller (Guest)
on 2006-03-24 03:50
(Received via mailing list)
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
This topic is locked and can not be replied to.