From 89389c7e72e8506fa461a36e4d1ff67366f9e61a Mon Sep 17 00:00:00 2001 From: claudiob Date: Mon, 30 Mar 2015 20:36:25 -0700 Subject: Fix doc: set_callback also accepts an array of if: When Active Record calls `set_callback` inside `after_commit`, [these lines of code](https://github.com/rails/rails/blob/master/activerecord/lib/active_record/transactions.rb#L276) pass an **array** of methods as the `:if` condition: ```ruby options[:if] = Array(options[:if]) options[:if] << "transaction_include_any_action?(#{fire_on})" ``` That made me realize that anyone could pass an **array** of `:if` and `:unless` conditions to `set_callback`, since Active Support transforms these conditions into an array anyways in [these lines of code](https://github.com/rails/rails/blob/master/activesupport/lib/active_support/callbacks.rb#L365): ```ruby @if = Array(options[:if]) @unless = Array(options[:unless]) ``` Long story short, this commit updates the documentation of the `set_callback` method to explain that arrays are also accepted. It also replaces +false+ and +true+ with false and true, since any _falsey_ or _truthy_ value will work. [ci skip] --- activesupport/lib/active_support/callbacks.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 08520b1077..9cf09ab266 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -663,10 +663,12 @@ module ActiveSupport # # ===== Options # - # * :if - A symbol naming an instance method or a proc; the - # callback will be called only when it returns a +true+ value. - # * :unless - A symbol naming an instance method or a proc; the - # callback will be called only when it returns a +false+ value. + # * :if - A symbol, a string or an array of symbols and strings, + # each naming an instance method or a proc; the callback will be called + # only when they all return a true value. + # * :unless - A symbol, a string or an array of symbols and + # strings, each naming an instance method or a proc; the callback will + # be called only when they all return a false value. # * :prepend - If +true+, the callback will be prepended to the # existing chain rather than appended. def set_callback(name, *filter_list, &block) -- cgit v1.2.3