Skip to content

Commit

Permalink
attr_accessor_with_default should raise an ArgumentError not a Runtim…
Browse files Browse the repository at this point in the history
…eError
  • Loading branch information
tenderlove committed Sep 24, 2010
1 parent a348ffc commit a0db7be
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Expand Up @@ -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
Expand Down
Expand Up @@ -26,6 +26,6 @@ def test_default_proc
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

0 comments on commit a0db7be

Please sign in to comment.