Sha256: 61221f0f2fcfcfe0f803cf779e0fcee39b319b4bdca6de5c95ac29b2d89e4368
Contents?: true
Size: 904 Bytes
Versions: 4
Compression:
Stored size: 904 Bytes
Contents
# attr_* style accessors for class-variables that can accessed both on an instance and class level. class Class #:nodoc: def cattr_reader(*syms) syms.each do |sym| class_eval <<-EOS if ! defined? @@#{sym.id2name} @@#{sym.id2name} = nil end def self.#{sym.id2name} @@#{sym} end def #{sym.id2name} self.class.#{sym.id2name} end EOS end end def cattr_writer(*syms) syms.each do |sym| class_eval <<-EOS if ! defined? @@#{sym.id2name} @@#{sym.id2name} = nil end def self.#{sym.id2name}=(obj) @@#{sym.id2name} = obj end def #{sym.id2name}=(obj) self.class.#{sym.id2name}=(obj) end EOS end end def cattr_accessor(*syms) cattr_reader(*syms) cattr_writer(*syms) end end
Version data entries
4 entries across 4 versions & 1 rubygems