aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/object_and_class_ext_test.rb
diff options
context:
space:
mode:
authorraggi <jftucker@gmail.com>2010-10-27 06:10:01 +0800
committerJosé Valim <jose.valim@gmail.com>2010-11-14 17:23:44 +0800
commite6d14279b881d8482c124bd55d0830a7ddcbcb0e (patch)
treec248862e1b261b86afcdebe44fa773f1101f71c1 /activesupport/test/core_ext/object_and_class_ext_test.rb
parentf43e5d160bf9708ad50b58c8168e38579769e024 (diff)
downloadrails-e6d14279b881d8482c124bd55d0830a7ddcbcb0e.tar.gz
rails-e6d14279b881d8482c124bd55d0830a7ddcbcb0e.tar.bz2
rails-e6d14279b881d8482c124bd55d0830a7ddcbcb0e.zip
Add support for try to just yield the object to a block if no method is to be called. Kind of like a tap_if_present.
Diffstat (limited to 'activesupport/test/core_ext/object_and_class_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/object_and_class_ext_test.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb
index 64f339ed90..398e6ca9b2 100644
--- a/activesupport/test/core_ext/object_and_class_ext_test.rb
+++ b/activesupport/test/core_ext/object_and_class_ext_test.rb
@@ -134,4 +134,14 @@ class ObjectTryTest < Test::Unit::TestCase
def test_false_try
assert_equal 'false', false.try(:to_s)
end
+
+ def test_try_only_block
+ assert_equal @string.reverse, @string.try { |s| s.reverse }
+ end
+
+ def test_try_only_block_nil
+ ran = false
+ nil.try { ran = true }
+ assert_equal false, ran
+ end
end