Skip to content

Commit 908ccc1

Browse files
authored
Merge pull request rails#42173 from okuramasafumi/improve-docs-of-activesupport-callbacks
[ci-skip] Improve doc for `ActiveSupport::Callbacks.skip_callback`
2 parents 67feef3 + abd4027 commit 908ccc1

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

activesupport/lib/active_support/callbacks.rb

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,10 +676,32 @@ def set_callback(name, *filter_list, &block)
676676
# <tt>:unless</tt> options may be passed in order to control when the
677677
# callback is skipped.
678678
#
679-
# class Writer < Person
680-
# skip_callback :validate, :before, :check_membership, if: -> { age > 18 }
679+
# class Writer < PersonRecord
680+
# attr_accessor :age
681+
# skip_callback :save, :before, :saving_message, if: -> { age > 18 }
681682
# end
682683
#
684+
# When if option returns true, callback is skipped.
685+
#
686+
# writer = Writer.new
687+
# writer.age = 20
688+
# writer.save
689+
#
690+
# Output:
691+
# - save
692+
# saved
693+
#
694+
# When if option returns false, callback is NOT skipped.
695+
#
696+
# young_writer = Writer.new
697+
# young_writer.age = 17
698+
# young_writer.save
699+
#
700+
# Output:
701+
# saving...
702+
# - save
703+
# saved
704+
#
683705
# An <tt>ArgumentError</tt> will be raised if the callback has not
684706
# already been set (unless the <tt>:raise</tt> option is set to <tt>false</tt>).
685707
def skip_callback(name, *filter_list, &block)

0 commit comments

Comments
 (0)