diff options
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/attr_accessor_with_default.rb | 5 | ||||
-rw-r--r-- | activesupport/test/core_ext/module/attr_accessor_with_default_test.rb | 2 |
2 files changed, 3 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 bfedbbb256..7b19aa059d 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 @@ -18,9 +18,8 @@ class Module # # attr_accessor_with_default(:element_name) { name.underscore } # - def attr_accessor_with_default(sym, default = nil, &block) - raise 'Default value or block required' unless !default.nil? || block - define_method(sym, block_given? ? block : Proc.new { default }) + def attr_accessor_with_default(sym, default = Proc.new) + define_method(sym, block_given? ? default : 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 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 9494ca9ef6..b9b60c4d6d 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 @@ -26,6 +26,6 @@ class AttrAccessorWithDefaultTest < Test::Unit::TestCase end def test_invalid_args - assert_raise(RuntimeError) {@target.attr_accessor_with_default :foo} + assert_raise(ArgumentError) {@target.attr_accessor_with_default :foo} end end |