Skip to content

Commit c2c7e20

Browse files
authored
Declare block param on NilClass#try and NilClass#try! (rails#55278)
With ruby 3.4, a warning is raised when a block is passed to a method and the method does not define the block param. This commit solves it by ensuring that the method signature of try and try! on NilClass is similar to Tryable.
1 parent a34563b commit c2c7e20

File tree

1 file changed

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

1 file changed

+2
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,14 @@ class NilClass
145145
#
146146
# With +try+
147147
# @person.try(:children).try(:first).try(:name)
148-
def try(*)
148+
def try(*, &)
149149
nil
150150
end
151151

152152
# Calling +try!+ on +nil+ always returns +nil+.
153153
#
154154
# nil.try!(:name) # => nil
155-
def try!(*)
155+
def try!(*, &)
156156
nil
157157
end
158158
end

0 commit comments

Comments
 (0)