On Thu, Jun 21, 2012 at 2:33 PM, Iain Barnett <[email protected]> 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 = token_pairs.map { |k,v|
      [k,v].map { |t|
        case t

into

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

and save an Array creation.

Cheers

robert

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

-- You received this message because you are subscribed to the Google Groups 
ruby-talk-google group. To post to this group, send email to 
[email protected]. To unsubscribe from this group, send email 
to [email protected]. For more options, visit this 
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en

Reply via email to