提交 d96a1b62 编写于 作者: R Rafael Mendonça França

Merge pull request #21158 from lsylvester/only-invoke-mattr_accessor-default-block-once

Prevent the default block for mattr_accessor being called multiple times
......@@ -206,7 +206,7 @@ def #{sym}=(obj)
# Person.class_variable_get("@@hair_colors") # => [:brown, :black, :blonde, :red]
def mattr_accessor(*syms, &blk)
mattr_reader(*syms, &blk)
mattr_writer(*syms, &blk)
mattr_writer(*syms)
end
alias :cattr_accessor :mattr_accessor
end
......@@ -76,4 +76,10 @@ def test_should_use_default_value_if_block_passed
assert_equal 'default_reader_value', @module.defr
assert_equal 'default_writer_value', @module.class_variable_get('@@defw')
end
def test_should_not_invoke_default_value_block_multiple_times
count = 0
@module.cattr_accessor(:defcount){ count += 1 }
assert_equal 1, count
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册