On 21 Jun 2012, at 14:30, Robert Klemme wrote:

> On Thu, Jun 21, 2012 at 2:33 PM, Iain Barnett <iainspeed / gmail.com> =
wrote:
>=20
>> If you're still interested, the code in question is at =
https://github.com/yb66/sequel/blob/master/lib/sequel/extensions/pg_hstore=
.rb. The method(s) would be a Hash#to_hstore and a String#from_hstore. =
When I get a chance I'm going to make it into its own gem (on the advice =
of the maintainer) and I'll consider whether it's a good idea to =
continue with the monkey patches.
>=20
> I my world String#from_hstore would be a class method at least.  I
> would also not cache @result in the String because that will prompt
> all sorts of inconsistency issues when the String is changed.
> Actually I'd rather have method HStore.from_string(str) and
> HStore#to_string or maybe even HStore.from_db_string(str) and
> HStore#to_db_string.
>=20
> I am not sure I understand yet why you have three types involved:
> String, Hash and HStore.  You certainly need String and HStore.  But I
> would consider conversion to or from Hash just as a convenience
> feature of HStore i.e. to easily create one.  That would make changing
> Hash superfluous.  And all conversion methods could go into HStore as
> explained above.
>=20
> Btw, you can turn
>=20
>    token_pairs =3D token_pairs.map { |k,v|
>      [k,v].map { |t|
>        case t
>=20
> into
>=20
>    token_pairs =3D token_pairs.map { |a|
>      a.map { |t|
>        case t
>=20
> and save an Array creation.
>=20
> Cheers
>=20
> robert
>=20

Thanks Robert, I'm grateful for the advice.

Regards,
Iain