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.  In the case of plugins, usually a class 
instance variable that is copied into subclasses (see 
Sequel::Plugins.inherited_instance_variables).  There are plenty of 
examples in the plugins that ship with Sequel.
 

> Each model *instance* needs to know its primary key, which it sounds like 
> I’ll be able to get for free if I switch to a plug-in, but the name of the 
> table that’s storing the properties is the same for all the instances. I 
> could reconstruct it anew for each instance, but it seems like something 
> that should be done once, for the class.
>

Sequel::Model#pk returns the primary key value for the instance.  A class 
instance variable and class accessor method for the table storing the 
properties is how it would generally be done in Sequel.

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.

Reply via email to