diff options
-rw-r--r-- | activesupport/lib/active_support/class_attribute_accessors.rb | 47 | ||||
-rw-r--r-- | activesupport/lib/active_support/module_attribute_accessors.rb | 37 |
2 files changed, 29 insertions, 55 deletions
diff --git a/activesupport/lib/active_support/class_attribute_accessors.rb b/activesupport/lib/active_support/class_attribute_accessors.rb index bb043f8e98..93a7d48f69 100644 --- a/activesupport/lib/active_support/class_attribute_accessors.rb +++ b/activesupport/lib/active_support/class_attribute_accessors.rb @@ -1,55 +1,42 @@ -# Extends the class object with class and instance accessors for class attributes, +# Extends the class object with class and instance accessors for class attributes, # just like the native attr* accessors for instance attributes. class Class # :nodoc: def cattr_reader(*syms) - syms.select { |sym| sym.respond_to?(:id2name) }.each do |sym| - class_eval <<-EOS - if ! defined? @@#{sym.id2name} - @@#{sym.id2name} = nil - end - - def self.#{sym.id2name} - @@#{sym} + syms.flatten.each do |sym| + class_eval(<<-EOS, __FILE__, __LINE__) + unless defined? @@#{sym} + @@#{sym} = nil end - def #{sym.id2name} + def self.#{sym} @@#{sym} end - def call_#{sym.id2name} - case @@#{sym.id2name} - when Symbol then send(@@#{sym}) - when Proc then @@#{sym}.call(self) - when String then @@#{sym} - else nil - end + def #{sym} + @@#{sym} end EOS end end - + def cattr_writer(*syms) - syms.select { |sym| sym.respond_to?(:id2name) }.each do |sym| - class_eval <<-EOS - if ! defined? @@#{sym.id2name} - @@#{sym.id2name} = nil - end - - def self.#{sym.id2name}=(obj) - @@#{sym.id2name} = obj + syms.flatten.each do |sym| + class_eval(<<-EOS, __FILE__, __LINE__) + unless defined? @@#{sym} + @@#{sym} = nil end - def self.set_#{sym.id2name}(obj) - @@#{sym.id2name} = obj + def self.#{sym}=(obj) + @@#{sym} = obj end - def #{sym.id2name}=(obj) + def #{sym}=(obj) @@#{sym} = obj end EOS end end - + def cattr_accessor(*syms) cattr_reader(*syms) cattr_writer(*syms) diff --git a/activesupport/lib/active_support/module_attribute_accessors.rb b/activesupport/lib/active_support/module_attribute_accessors.rb index 3d466e4493..fe4f8a4fc0 100644 --- a/activesupport/lib/active_support/module_attribute_accessors.rb +++ b/activesupport/lib/active_support/module_attribute_accessors.rb @@ -3,47 +3,34 @@ class Module # :nodoc: def mattr_reader(*syms) syms.each do |sym| - class_eval <<-EOS - if ! defined? @@#{sym.id2name} - @@#{sym.id2name} = nil + class_eval(<<-EOS, __FILE__, __LINE__) + unless defined? @@#{sym} + @@#{sym} = nil end - def self.#{sym.id2name} + def self.#{sym} @@#{sym} end - def #{sym.id2name} + def #{sym} @@#{sym} end - - def call_#{sym.id2name} - case @@#{sym.id2name} - when Symbol then send(@@#{sym}) - when Proc then @@#{sym}.call(self) - when String then @@#{sym} - else nil - end - end EOS end end def mattr_writer(*syms) syms.each do |sym| - class_eval <<-EOS - if ! defined? @@#{sym.id2name} - @@#{sym.id2name} = nil + class_eval(<<-EOS, __FILE__, __LINE__) + unless defined? @@#{sym} + @@#{sym} = nil end - def self.#{sym.id2name}=(obj) - @@#{sym.id2name} = obj - end - - def self.set_#{sym.id2name}(obj) - @@#{sym.id2name} = obj + def self.#{sym}=(obj) + @@#{sym} = obj end - def #{sym.id2name}=(obj) + def #{sym}=(obj) @@#{sym} = obj end EOS @@ -54,4 +41,4 @@ class Module # :nodoc: mattr_reader(*syms) mattr_writer(*syms) end -end
\ No newline at end of file +end |