From 5e85a1c7f835249d276d6868a9520f803be46159 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Sun, 28 Jan 2007 01:18:51 +0000 Subject: Added :instance_writer option to #mattr_writer/accessor, #cattr_writer/accessor, and #class_inheritable_writer to skip the creation of the instance writer. [Rick] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6050 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/active_support/core_ext/class/attribute_accessors.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activesupport/lib/active_support/core_ext/class/attribute_accessors.rb') diff --git a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb index 93a7d48f69..79247e00cb 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb @@ -3,6 +3,7 @@ class Class # :nodoc: def cattr_reader(*syms) syms.flatten.each do |sym| + next if sym.is_a?(Hash) class_eval(<<-EOS, __FILE__, __LINE__) unless defined? @@#{sym} @@#{sym} = nil @@ -20,6 +21,7 @@ class Class # :nodoc: end def cattr_writer(*syms) + options = syms.last.is_a?(Hash) ? syms.pop : {} syms.flatten.each do |sym| class_eval(<<-EOS, __FILE__, __LINE__) unless defined? @@#{sym} @@ -30,9 +32,11 @@ class Class # :nodoc: @@#{sym} = obj end + #{" def #{sym}=(obj) @@#{sym} = obj end + " unless options[:instance_writer] == false } EOS end end -- cgit v1.2.3