aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2014-10-22 16:23:55 -0700
committerGodfrey Chan <godfreykfc@gmail.com>2014-10-22 16:23:55 -0700
commit07b80c128fc8ba4883fd85e14a99c3dd30d598cb (patch)
tree038533507b71043abab8a2c95318685770b10f8a /activesupport
parent19d698d2b45ca33d8709c1993e39d7d9df284e3d (diff)
parente98f2a74eb20e2b0866b66130501f8480798dd4c (diff)
downloadrails-07b80c128fc8ba4883fd85e14a99c3dd30d598cb.tar.gz
rails-07b80c128fc8ba4883fd85e14a99c3dd30d598cb.tar.bz2
rails-07b80c128fc8ba4883fd85e14a99c3dd30d598cb.zip
Merge pull request #17361 from aripollak/try-bang-parity
Bring try! into parity with try.
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/object/try.rb2
-rw-r--r--activesupport/test/core_ext/object/try_test.rb12
2 files changed, 9 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/try.rb b/activesupport/lib/active_support/core_ext/object/try.rb
index 31919474ed..112ec05e15 100644
--- a/activesupport/lib/active_support/core_ext/object/try.rb
+++ b/activesupport/lib/active_support/core_ext/object/try.rb
@@ -59,7 +59,7 @@ class Object
# 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
diff --git a/activesupport/test/core_ext/object/try_test.rb b/activesupport/test/core_ext/object/try_test.rb
index 225c20fa36..efc6beaf02 100644
--- a/activesupport/test/core_ext/object/try_test.rb
+++ b/activesupport/test/core_ext/object/try_test.rb
@@ -30,10 +30,6 @@ class ObjectTryTest < ActiveSupport::TestCase
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 @@ class ObjectTryTest < ActiveSupport::TestCase
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 @@ class ObjectTryTest < ActiveSupport::TestCase
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