aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/core_ext/class/attribute_accessors.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/class/attribute_accessors.rb13
1 files changed, 8 insertions, 5 deletions
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 1602a609eb..83d154be5c 100644
--- a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
+++ b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
@@ -10,8 +10,8 @@ require 'active_support/core_ext/array/extract_options'
# Person.hair_colors = [:brown, :black, :blonde, :red]
class Class
def cattr_reader(*syms)
+ options = syms.extract_options!
syms.flatten.each do |sym|
- next if sym.is_a?(Hash)
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
unless defined? @@#{sym} # unless defined? @@hair_colors
@@#{sym} = nil # @@hair_colors = nil
@@ -20,11 +20,14 @@ class Class
def self.#{sym} # def self.hair_colors
@@#{sym} # @@hair_colors
end # end
- #
- def #{sym} # def hair_colors
- @@#{sym} # @@hair_colors
- end # end
EOS
+ unless options[:instance_reader] == false
+ class_eval(<<-EOS, __FILE__, __LINE__)
+ def #{sym} # def hair_colors
+ @@#{sym} # @@hair_colors
+ end # end
+ EOS
+ end
end
end