From: kris Date: 2006-04-10T22:29:38+09:00 Subject: Re: Adding in class attribute with a Module Thanks very much for all the examples. I think I need to clarify, basically I have a base class called "System" from which all my models decend. This class has a class attribute called user_id which is set to the current_user every request by application.rb: BASE MODEL CLASS class System < ActiveRecord::Base cattr_accessor :user_id end MODEL class Documents < System # this model know the current user's id end APPLICATION CONTROLLER class ApplicationController < ActionController::Base before_filter :set_user # set class attribute for all models def set_user if logged_in? System.user_id = current_user.id end end end By using a class attribute instead of a instance attribute I can set the current user id for all models at once. This works but I want to use a module/mixin instead of inheritance. Many thanks again. PS. I didnt write cattr_accessor. I'm using Rails but I dont think it is opart of that? unknown wrote: > Hi -- > > On Mon, 10 Apr 2006, kris wrote: > >> Is it possible to add class attributes (cattr_accessor) using a module? >> If so could you give an example? > > There's no cattr_accessor method in Ruby. If you've written one, or > are using one written by someone else, you'll have to show us what it > does before we can tell you how to use it :-) > > > David > > -- > David A. Black (dblack@wobblini.net) > Ruby Power and Light, LLC (http://www.rubypowerandlight.com) > > "Ruby for Rails" coming in PDF April 15, and in paper May 1! > http://www.manning.com/black -- Posted via http://www.ruby-forum.com/.