From b081948bb3e1a6874f133140bf07e7fb9d3359d9 Mon Sep 17 00:00:00 2001 From: Kabari Hendrick Date: Sun, 14 Mar 2010 01:33:45 -0600 Subject: fixing inconsistency with cattr_reader and matter_reader [#4172 state:resolved] Signed-off-by: wycats --- .../active_support/core_ext/class/attribute_accessors.rb | 13 ++++++++----- .../active_support/core_ext/module/attribute_accessors.rb | 14 +++++++++----- 2 files changed, 17 insertions(+), 10 deletions(-) (limited to 'activesupport/lib/active_support') 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 @@ -19,12 +19,15 @@ 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 diff --git a/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb b/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb index 131b512944..c315fd5812 100644 --- a/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb +++ b/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb @@ -2,7 +2,7 @@ require 'active_support/core_ext/array/extract_options' class Module def mattr_reader(*syms) - syms.extract_options! + options = syms.extract_options! syms.each do |sym| class_eval(<<-EOS, __FILE__, __LINE__ + 1) unless defined? @@#{sym} # unless defined? @@pagination_options @@ -12,11 +12,15 @@ class Module def self.#{sym} # def self.pagination_options @@#{sym} # @@pagination_options end # end - - def #{sym} # def pagination_options - @@#{sym} # @@pagination_options - 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 -- cgit v1.2.3