From: "David A. Black" Date: 2008-05-11T09:40:36+09:00 Subject: Re: Sharing variables between classes and instances Hi -- On Sun, 11 May 2008, Leon Bogaert wrote: > Hi all, > > What I'm trying to achieve: add a variable to a class. Fill it with > data. Every nstance of that class should have access to the data in that > variable. But I want every instance be able to modify that variable, > without modifying the original value of the variable. I'm not sure what you mean exactly. Do you mean each instance should have a copy of the object? If so, I would just do: class Tester def self.vars @vars ||= [] end def self.add_var(var) self.vars << var end def vars @vars || self.class.vars end def add_var(var) @vars ||= self.class.vars.dup vars << var end end That gives the results you expect in your test. David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin INTRO TO RAILS June 24-27 London (Skills Matter) See http://www.rubypal.com for details and updates!