attr_accessor_with_default should raise an ArgumentError not a RuntimeError
This commit is contained in:
parent
a348ffcb2d
commit
a0db7be4af
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user