From 917e81a8081df184c8428e8a3df3f82fc88fb586 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Mon, 3 May 2021 03:31:27 +0900 Subject: [PATCH] Fix and improve the method signature for `try` and `try!` Expand `try(*a, &b)` to `try(*args, &block)`, and fix invalid `a*`. --- .../lib/active_support/core_ext/object/try.rb | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/object/try.rb b/activesupport/lib/active_support/core_ext/object/try.rb index ceb032ffe82..6fda869a630 100644 --- a/activesupport/lib/active_support/core_ext/object/try.rb +++ b/activesupport/lib/active_support/core_ext/object/try.rb @@ -4,28 +4,28 @@ require "delegate" module ActiveSupport module Tryable #:nodoc: - def try(method_name = nil, *args, &b) + def try(method_name = nil, *args, &block) if method_name.nil? && block_given? - if b.arity == 0 - instance_eval(&b) + if block.arity == 0 + instance_eval(&block) else yield self end elsif respond_to?(method_name) - public_send(method_name, *args, &b) + public_send(method_name, *args, &block) end end ruby2_keywords(:try) - def try!(method_name = nil, *args, &b) + def try!(method_name = nil, *args, &block) if method_name.nil? && block_given? - if b.arity == 0 - instance_eval(&b) + if block.arity == 0 + instance_eval(&block) else yield self end else - public_send(method_name, *args, &b) + public_send(method_name, *args, &block) end end ruby2_keywords(:try!) @@ -39,7 +39,7 @@ class Object # :method: try # # :call-seq: - # try(*a, &b) + # try(*args, &block) # # Invokes the public method whose name goes as first argument just like # +public_send+ does, except that if the receiver does not respond to it the @@ -104,7 +104,7 @@ class Object # :method: try! # # :call-seq: - # try!(*a, &b) + # try!(*args, &block) # # Same as #try, but raises a +NoMethodError+ exception if the receiver is # not +nil+ and does not implement the tried method. @@ -121,7 +121,7 @@ class Delegator # :method: try # # :call-seq: - # try(a*, &b) + # try(*args, &block) # # See Object#try @@ -129,7 +129,7 @@ class Delegator # :method: try! # # :call-seq: - # try!(a*, &b) + # try!(*args, &block) # # See Object#try! end