From 70bb7beac39255dc34419c75359502fd59b3d3c1 Mon Sep 17 00:00:00 2001 From: Krekoten' Marjan Date: Sat, 18 Sep 2010 23:48:43 +0300 Subject: [PATCH] Fix 'warning: method redefined' [#5551 state:resolved] --- .../core_ext/module/attr_accessor_with_default.rb | 8 ++++---- .../module/attr_accessor_with_default_test.rb | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/module/attr_accessor_with_default.rb b/activesupport/lib/active_support/core_ext/module/attr_accessor_with_default.rb index bfedbbb..62a5b03 100644 --- a/activesupport/lib/active_support/core_ext/module/attr_accessor_with_default.rb +++ b/activesupport/lib/active_support/core_ext/module/attr_accessor_with_default.rb @@ -22,10 +22,10 @@ class Module raise 'Default value or block required' unless !default.nil? || block define_method(sym, block_given? ? block : Proc.new { default }) module_eval(<<-EVAL, __FILE__, __LINE__ + 1) - def #{sym}=(value) # def age=(value) - class << self; attr_reader :#{sym} end # class << self; attr_reader :age end - @#{sym} = value # @age = value - end # end + def #{sym}=(value) # def age=(value) + class << self; attr_accessor :#{sym} end # class << self; attr_accessor :age end + @#{sym} = value # @age = value + end # end EVAL end end diff --git a/activesupport/test/core_ext/module/attr_accessor_with_default_test.rb b/activesupport/test/core_ext/module/attr_accessor_with_default_test.rb index 9494ca9..f708cbc 100644 --- a/activesupport/test/core_ext/module/attr_accessor_with_default_test.rb +++ b/activesupport/test/core_ext/module/attr_accessor_with_default_test.rb @@ -28,4 +28,13 @@ class AttrAccessorWithDefaultTest < Test::Unit::TestCase def test_invalid_args assert_raise(RuntimeError) {@target.attr_accessor_with_default :foo} end + + def test_no_warning_method_redefined + @target.attr_accessor_with_default(:foo, :bar) + result = capture(:stderr) do + @instance.foo = :bar + @instance.foo = :bar + end + assert_not_match /warning: method redefined/, result + end end -- 1.7.2