Hi --

On Sat, 21 Jan 2006, Todd Breiholz wrote:

> Assume the following structure:
>
> class Base
> end
>
> class Account < Base
> end
>
> class Opportunity < Base
> end
>
>
> I want to have a class variable Account.fields that is different than
> Opportunity.fields, so that all instances of Account can reference the
> Account.fields and all instances if Opportunity can reference
> Opportunity.fields and get the correct results.

Account.fields and Opportunity fields are methods, not variables.  You
can easily define them:

   class Account < Base
     def self.fields
       # code here, possibly using instance variable to hold info
     end
   # etc.
   end

Or you could put it in a module and extend the various classes with
it.  (The best exact way will depend on what's in the method.)

For the instances:

   class Base
     def fields
       self.class.fields
     end
   end

That way, each object will know to query its own class to get the
right fields method.


David

-- 
David A. Black
dblack / wobblini.net

"Ruby for Rails", from Manning Publications, coming April 2006!
http://www.manning.com/books/black