On Monday, April 28, 2014 8:36:21 PM UTC-7, Snarke wrote: > > On Apr 28, 2014, at 19:55 , Jeremy Evans wrote: > > On Monday, April 28, 2014 5:49:10 PM UTC-7, Snarke wrote: > > > Second, avoid using class variables in ruby, they are almost always a > bad idea. > > > > What is my alternative? > > > > Depending on the situation, either a class instance variable with a > class accessor method or a constant. > > I was afraid you were going to say that. I read quite a bit of Q&As > dealing with class variables when trying to figure out how to best code > that module, and, frankly, I’m still completely in the dark as to what > exactly “class instance variable” is even supposed to mean. The whole > ‘meta’ design thing is mental quicksand, and I haven’t found a good > explanation yet, although this has all mostly just been increased pressure > for me to actually open up and read my copy of Ruby Metaprogramming. :) >
Classes are objects and like any other objects, can have their own instance variables. These instance variables are not copied into subclasses by default, so in general you need to copy them into subclasses manually (which Sequel provides helper methods to do). > However, I started working on folding Postgres’s hstore into my models. It > took me a bit to figure out how to get it all lined up. (First do the > 'Sequel.extension(:pg_hstore, :pg_hstore_ops)’ call, then define DB, *then* > do ‘DB.extension :pg_hstore’. Aha!) > You shouldn't need to do that. Just: DB = Sequel.connect(...) DB.extension :pg_hstore Sequel.extension :pg_hstore_ops > My only defense is that the Postgres people went and snuck the whole > ‘hstore’ thing into an appendix, and did so long after I’d started using > Postgres, so I wasn’t keeping a close enough eye on what they were up to > with their upgrades. Starting with PostgreSQL 9.4, the jsonb type exists, which is more flexible than hstore while still being able to be indexed, and unlike hstore, it is a core type instead of an extension. So after you upgrade to PostgreSQL 9.4, you'll probably want to convert your hstore type to a jsonb type. Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
