Skip to content

Commit 917e81a

Browse files
committed
Fix and improve the method signature for try and try!
Expand `try(*a, &b)` to `try(*args, &block)`, and fix invalid `a*`.
1 parent ab13f95 commit 917e81a

File tree

1 file changed

+12
-12
lines changed
  • activesupport/lib/active_support/core_ext/object

1 file changed

+12
-12
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@
44

55
module ActiveSupport
66
module Tryable #:nodoc:
7-
def try(method_name = nil, *args, &b)
7+
def try(method_name = nil, *args, &block)
88
if method_name.nil? && block_given?
9-
if b.arity == 0
10-
instance_eval(&b)
9+
if block.arity == 0
10+
instance_eval(&block)
1111
else
1212
yield self
1313
end
1414
elsif respond_to?(method_name)
15-
public_send(method_name, *args, &b)
15+
public_send(method_name, *args, &block)
1616
end
1717
end
1818
ruby2_keywords(:try)
1919

20-
def try!(method_name = nil, *args, &b)
20+
def try!(method_name = nil, *args, &block)
2121
if method_name.nil? && block_given?
22-
if b.arity == 0
23-
instance_eval(&b)
22+
if block.arity == 0
23+
instance_eval(&block)
2424
else
2525
yield self
2626
end
2727
else
28-
public_send(method_name, *args, &b)
28+
public_send(method_name, *args, &block)
2929
end
3030
end
3131
ruby2_keywords(:try!)
@@ -39,7 +39,7 @@ class Object
3939
# :method: try
4040
#
4141
# :call-seq:
42-
# try(*a, &b)
42+
# try(*args, &block)
4343
#
4444
# Invokes the public method whose name goes as first argument just like
4545
# +public_send+ does, except that if the receiver does not respond to it the
@@ -104,7 +104,7 @@ class Object
104104
# :method: try!
105105
#
106106
# :call-seq:
107-
# try!(*a, &b)
107+
# try!(*args, &block)
108108
#
109109
# Same as #try, but raises a +NoMethodError+ exception if the receiver is
110110
# not +nil+ and does not implement the tried method.
@@ -121,15 +121,15 @@ class Delegator
121121
# :method: try
122122
#
123123
# :call-seq:
124-
# try(a*, &b)
124+
# try(*args, &block)
125125
#
126126
# See Object#try
127127

128128
##
129129
# :method: try!
130130
#
131131
# :call-seq:
132-
# try!(a*, &b)
132+
# try!(*args, &block)
133133
#
134134
# See Object#try!
135135
end

0 commit comments

Comments
 (0)