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 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (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 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 -- cgit v1.2.3 From edbb9526d315444d560362487b78e03b2f3d7a61 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 27 Mar 2010 11:26:12 -0300 Subject: flatten not needed here MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- .../lib/active_support/core_ext/class/attribute_accessors.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (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 83d154be5c..be34a5a96f 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb @@ -11,7 +11,7 @@ require 'active_support/core_ext/array/extract_options' class Class def cattr_reader(*syms) options = syms.extract_options! - syms.flatten.each do |sym| + syms.each do |sym| class_eval(<<-EOS, __FILE__, __LINE__ + 1) unless defined? @@#{sym} # unless defined? @@hair_colors @@#{sym} = nil # @@hair_colors = nil @@ -33,7 +33,7 @@ class Class def cattr_writer(*syms) options = syms.extract_options! - syms.flatten.each do |sym| + syms.each do |sym| class_eval(<<-EOS, __FILE__, __LINE__ + 1) unless defined? @@#{sym} # unless defined? @@hair_colors @@#{sym} = nil # @@hair_colors = nil -- cgit v1.2.3 From 820e3a8491100ed24a6a33df07afee341956a45c Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 27 Mar 2010 11:29:10 -0300 Subject: LINE on class_eval need + 1, also removed comments [#4281 state:committed] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- .../core_ext/class/attribute_accessors.rb | 51 ++++++++++++---------- 1 file changed, 27 insertions(+), 24 deletions(-) (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 be34a5a96f..feef5d2d57 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute_accessors.rb @@ -13,19 +13,20 @@ class Class options = syms.extract_options! syms.each do |sym| class_eval(<<-EOS, __FILE__, __LINE__ + 1) - unless defined? @@#{sym} # unless defined? @@hair_colors - @@#{sym} = nil # @@hair_colors = nil - end # end - # - def self.#{sym} # def self.hair_colors - @@#{sym} # @@hair_colors - end # end + unless defined? @@#{sym} + @@#{sym} = nil + end + + def self.#{sym} + @@#{sym} + end EOS + unless options[:instance_reader] == false - class_eval(<<-EOS, __FILE__, __LINE__) - def #{sym} # def hair_colors - @@#{sym} # @@hair_colors - end # end + class_eval(<<-EOS, __FILE__, __LINE__ + 1) + def #{sym} + @@#{sym} + end EOS end end @@ -35,20 +36,22 @@ class Class options = syms.extract_options! syms.each do |sym| class_eval(<<-EOS, __FILE__, __LINE__ + 1) - unless defined? @@#{sym} # unless defined? @@hair_colors - @@#{sym} = nil # @@hair_colors = nil - end # end - # - def self.#{sym}=(obj) # def self.hair_colors=(obj) - @@#{sym} = obj # @@hair_colors = obj - end # end - # - #{" # - def #{sym}=(obj) # def hair_colors=(obj) - @@#{sym} = obj # @@hair_colors = obj - end # end - " unless options[:instance_writer] == false } # # instance writer above is generated unless options[:instance_writer] == false + unless defined? @@#{sym} + @@#{sym} = nil + end + + def self.#{sym}=(obj) + @@#{sym} = obj + end EOS + + unless options[:instance_writer] == false + class_eval(<<-EOS, __FILE__, __LINE__ + 1) + def #{sym}=(obj) + @@#{sym} = obj + end + EOS + end self.send("#{sym}=", yield) if block_given? end end -- cgit v1.2.3