aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2005-11-21 07:29:12 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2005-11-21 07:29:12 +0000
commit3148216cbb2fb38c9c83ab91dde96ea25d46dc7c (patch)
treeb9ce88612227e645ff9524d2ec23fb28b204d574 /activesupport
parenta821c3dd932a06fe702baa404b46a46156d357ea (diff)
downloadrails-3148216cbb2fb38c9c83ab91dde96ea25d46dc7c.tar.gz
rails-3148216cbb2fb38c9c83ab91dde96ea25d46dc7c.tar.bz2
rails-3148216cbb2fb38c9c83ab91dde96ea25d46dc7c.zip
r3216@asus: jeremy | 2005-11-20 03:05:20 -0800
simplify cattr_ and mattr_accessor git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3128 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/class_attribute_accessors.rb47
-rw-r--r--activesupport/lib/active_support/module_attribute_accessors.rb37
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