diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-09-24 14:48:25 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-09-24 14:48:57 -0700 |
commit | a0db7be4aff6fc6ebf67bbbd441c47d678bd5195 (patch) | |
tree | 3169442c70ad9df7db96cd120057e3c51659f38d /activesupport | |
parent | a348ffcb2dd3819c76756d0ce0e88bc858e89ca5 (diff) | |
download | rails-a0db7be4aff6fc6ebf67bbbd441c47d678bd5195.tar.gz rails-a0db7be4aff6fc6ebf67bbbd441c47d678bd5195.tar.bz2 rails-a0db7be4aff6fc6ebf67bbbd441c47d678bd5195.zip |
attr_accessor_with_default should raise an ArgumentError not a RuntimeError
Diffstat (limited to 'activesupport')
-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 |