Skip to content

Commit 3c6cbad

Browse files
committed
Revert "don't raise NoMethodError the tried method doesn't exists"
This reverts commit 29a5aea.
1 parent f8beca0 commit 3c6cbad

File tree

2 files changed

+1
-3
lines changed

2 files changed

+1
-3
lines changed

activesupport/lib/active_support/core_ext/object/try.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ class Object
2828
def try(*a, &b)
2929
if a.empty? && block_given?
3030
yield self
31-
elsif !a.empty? && !respond_to?(a.first)
32-
nil
3331
else
3432
__send__(*a, &b)
3533
end

activesupport/test/core_ext/object_and_class_ext_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def setup
9999
def test_nonexisting_method
100100
method = :undefined_method
101101
assert !@string.respond_to?(method)
102-
assert_nil @string.try(method)
102+
assert_raise(NoMethodError) { @string.try(method) }
103103
end
104104

105105
def test_nonexisting_method_with_arguments

0 commit comments

Comments
 (0)