I think I've seen this somewhere, but I can not recall where. Is there
some sort of class or method that will convert a hash so that all keys
may be accessed via a String or a Symbol, where the two are mapped
intelligently, and automatically upon assignment/creation of a key?
So like:
h['A key'] == h[:a_key]
?
I usually use 'hashie' gem for this kind of stuff eg.
class Hash
include Hashie::Extensions::SymbolizeKeys
end
or,
class Hash
include Hashie::Extensions::MergeInitializer
include Hashie::Extensions::IndifferentAccess
end
etc.
···
On Mon, Jun 10, 2013 at 1:22 PM, Tamara Temple <tamouse.lists@gmail.com> wrote:
I think I've seen this somewhere, but I can not recall where. Is there
some sort of class or method that will convert a hash so that all keys
may be accessed via a String or a Symbol, where the two are mapped
intelligently, and automatically upon assignment/creation of a key?
So like:
h['A key'] == h[:a_key]
?
--
Pozdrawiam
Marcin Rzeźnicki
ActiveSupport::HashWithIndifferentAccess
···
On Mon, Jun 10, 2013 at 4:22 AM, Tamara Temple <tamouse.lists@gmail.com> wrote:
I think I've seen this somewhere, but I can not recall where.
h['A key'] == h[:a_key]
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
Thanks, looks like this is what I need.
···
On Jun 10, 2013 6:57 AM, "Marcin Rzeźnicki" <marcin.rzeznicki@gmail.com> wrote:
On Mon, Jun 10, 2013 at 1:22 PM, Tamara Temple <tamouse.lists@gmail.com> wrote:
>
> I think I've seen this somewhere, but I can not recall where. Is there
> some sort of class or method that will convert a hash so that all keys
> may be accessed via a String or a Symbol, where the two are mapped
> intelligently, and automatically upon assignment/creation of a key?
>
> So like:
>
> h['A key'] == h[:a_key]
>
> ?
>
I usually use 'hashie' gem for this kind of stuff eg.
class Hash
include Hashie::Extensions::SymbolizeKeys
end
or,
class Hash
include Hashie::Extensions::MergeInitializer
include Hashie::Extensions::IndifferentAccess
end
etc.
--
Pozdrawiam
Marcin Rzeźnicki