From: Florian Gross Date: 2005-03-31T00:29:45+09:00 Subject: Re: Defining a Class Accessor James Edward Gray II wrote: > I was playing around with an idea in another thread and ran into a > surprise. Can anyone explain the following to me? > > irb(main):015:0> class Module > irb(main):016:1> def cattr_accessor( *symbols ) > irb(main):017:2> symbols.each do |sym| > irb(main):018:3* eval "def self.#{sym}( ) @@#{sym} end > irb(main):019:3" def self.#{sym}=( value ) @@#{sym} = > value end" > irb(main):020:3> end > irb(main):021:2> end > irb(main):022:1> end Do you really need to use @@variables? From my experience they tend to cause trouble.