Class: Class
- Inherits:
-
Object
- Object
- Class
- Defined in:
- lib/active_record/support/class_attribute_accessors.rb
Overview
attr_* style accessors for class-variables that can accessed both on an instance and class level.
Instance Method Summary collapse
- #cattr_accessor(*syms) ⇒ Object
-
#cattr_reader(*syms) ⇒ Object
:nodoc:.
- #cattr_writer(*syms) ⇒ Object
Instance Method Details
#cattr_accessor(*syms) ⇒ Object
39 40 41 42 |
# File 'lib/active_record/support/class_attribute_accessors.rb', line 39 def cattr_accessor(*syms) cattr_reader(*syms) cattr_writer(*syms) end |
#cattr_reader(*syms) ⇒ Object
:nodoc:
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/active_record/support/class_attribute_accessors.rb', line 3 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 |
#cattr_writer(*syms) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/active_record/support/class_attribute_accessors.rb', line 21 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 |