File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed
activesupport/lib/active_support/core_ext/object Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 4
4
5
5
module ActiveSupport
6
6
module Tryable #:nodoc:
7
- def try ( method_name = nil , *args , &block )
8
- if method_name . nil ? && block_given?
7
+ def try ( *args , &block )
8
+ if args . empty ? && block_given?
9
9
if block . arity == 0
10
10
instance_eval ( &block )
11
11
else
12
12
yield self
13
13
end
14
- elsif respond_to? ( method_name )
15
- public_send ( method_name , *args , &block )
14
+ elsif respond_to? ( args . first )
15
+ public_send ( *args , &block )
16
16
end
17
17
end
18
18
ruby2_keywords ( :try )
19
19
20
- def try! ( method_name = nil , *args , &block )
21
- if method_name . nil ? && block_given?
20
+ def try! ( *args , &block )
21
+ if args . empty ? && block_given?
22
22
if block . arity == 0
23
23
instance_eval ( &block )
24
24
else
25
25
yield self
26
26
end
27
27
else
28
- public_send ( method_name , *args , &block )
28
+ public_send ( *args , &block )
29
29
end
30
30
end
31
31
ruby2_keywords ( :try! )
@@ -145,14 +145,14 @@ class NilClass
145
145
#
146
146
# With +try+
147
147
# @person.try(:children).try(:first).try(:name)
148
- def try ( _method_name = nil , *)
148
+ def try ( *)
149
149
nil
150
150
end
151
151
152
152
# Calling +try!+ on +nil+ always returns +nil+.
153
153
#
154
154
# nil.try!(:name) # => nil
155
- def try! ( _method_name = nil , *)
155
+ def try! ( *)
156
156
nil
157
157
end
158
158
end
You can’t perform that action at this time.
0 commit comments