class Class # Creates a class-variable attr_writer that can # be accessed both on an instance and class level. # # require 'facet/class/attr_writer' # # class MyClass # cattr_writer :a # def a # @@a # end # end # MyClass.a = 10 # mc = MyClass.new # mc.a #=> 10 # def cattr_writer(*syms) syms.each do |sym| class_eval <<-EOS if ! defined? @@#{sym} @@#{sym} = nil end def self.#{sym}=(obj) @@#{sym} = obj end def #{sym}=(obj) self.class.#{sym}=(obj) end EOS end end end