Skip to content

Commit 7076741

Browse files
authored
Merge pull request rails#54064 from Roriz/fix/symbol-proc-on-callbacks
Support symbol proc on callback conditional
2 parents a3ab6a9 + 2043d15 commit 7076741

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

activesupport/lib/active_support/callbacks.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,10 @@ def self.build(filter, callback)
498498
when Conditionals::Value
499499
ProcCall.new(filter)
500500
when ::Proc
501-
if filter.arity > 1
501+
case filter.arity
502+
when 2
502503
InstanceExec2.new(filter)
503-
elsif filter.arity > 0
504+
when 1, -2
504505
InstanceExec1.new(filter)
505506
else
506507
InstanceExec0.new(filter)

activesupport/test/callbacks_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ class ConditionalPerson < Record
189189
before_save Proc.new { |r| r.history << "b00m" }, if: Proc.new { |r| false }
190190
before_save Proc.new { |r| r.history << [:before_save, :proc] }, unless: Proc.new { |r| false }
191191
before_save Proc.new { |r| r.history << "b00m" }, unless: Proc.new { |r| true }
192+
before_save Proc.new { |r| r.history << "b00m" }, unless: proc(&:history)
193+
before_save Proc.new { |r| r.history << "b00m" }, unless: lambda(&:history)
192194
# symbol
193195
before_save Proc.new { |r| r.history << [:before_save, :symbol] }, if: :yes
194196
before_save Proc.new { |r| r.history << "b00m" }, if: :no

0 commit comments

Comments
 (0)