From: tamouse mailing lists Date: 2013-06-11T02:22:36+09:00 Subject: Re: Class or method to convert hash keys to enable either string or symbol access? --089e0158c09aa8440904ded00644 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Jun 10, 2013 6:57 AM, "Marcin Rze=C5=BAnicki" wrote: > > On Mon, Jun 10, 2013 at 1:22 PM, Tamara Temple 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'] =3D=3D 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=C5=BAnicki > Thanks, looks like this is what I need. --089e0158c09aa8440904ded00644 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On Jun 10, 2013 6:57 AM, "Marcin Rze=C5=BAnicki" <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 mappe= d
> > intelligently, and automatically upon assignment/creation of a ke= y?
> >
> > So like:
> >
> > =C2=A0 =C2=A0h['A key'] =3D=3D h[:a_key]
> >
> > ?
> >
>
> I usually use 'hashie' gem for this kind of stuff eg.
>
> class Hash
> =C2=A0 include Hashie::Extensions::SymbolizeKeys
> end
>
> or,
>
> =C2=A0 class Hash
> =C2=A0 =C2=A0 include Hashie::Extensions::MergeInitializer
> =C2=A0 =C2=A0 include Hashie::Extensions::IndifferentAccess
> =C2=A0 end
> etc.
>
> --
> Pozdrawiam
> Marcin Rze=C5=BAnicki
>

Thanks, looks like this is what I need.

--089e0158c09aa8440904ded00644--