提交 07b80c12 编写于 作者: G Godfrey Chan

Merge pull request #17361 from aripollak/try-bang-parity

Bring try! into parity with try.
......@@ -59,7 +59,7 @@ def try(*a, &b)
# does not implement the tried method.
def try!(*a, &b)
if a.empty? && block_given?
yield self
try(*a, &b)
else
public_send(*a, &b)
end
......
......@@ -30,10 +30,6 @@ def test_nonexisting_method_with_arguments_bang
assert_raise(NoMethodError) { @string.try!(method, 'llo', 'y') }
end
def test_try_only_block_bang
assert_equal @string.reverse, @string.try! { |s| s.reverse }
end
def test_valid_method
assert_equal 5, @string.try(:size)
end
......@@ -59,6 +55,10 @@ def test_try_only_block
assert_equal @string.reverse, @string.try { |s| s.reverse }
end
def test_try_only_block_bang
assert_equal @string.reverse, @string.try! { |s| s.reverse }
end
def test_try_only_block_nil
ran = false
nil.try { ran = true }
......@@ -69,6 +69,10 @@ def test_try_with_instance_eval_block
assert_equal @string.reverse, @string.try { reverse }
end
def test_try_with_instance_eval_block_bang
assert_equal @string.reverse, @string.try! { reverse }
end
def test_try_with_private_method_bang
klass = Class.new do
private
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册