On Thu, Jun 21, 2012 at 2:33 PM, Iain Barnett <iainspeed / gmail.com> wrote:

> 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.

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.

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.

Btw, you can turn

    token_pairs =3D token_pairs.map { |k,v|
      [k,v].map { |t|
        case t

into

    token_pairs =3D token_pairs.map { |a|
      a.map { |t|
        case t

and save an Array creation.

Cheers

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/