mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
[ci skip] Add Doc of with_options for the case when inherited default options and original options have same keys
This commit is contained in:
parent
0ab075e75f
commit
68fd1a3b23
1 changed files with 15 additions and 1 deletions
|
@ -47,7 +47,21 @@ class Object
|
|||
# end
|
||||
#
|
||||
# <tt>with_options</tt> can also be nested since the call is forwarded to its receiver.
|
||||
# Each nesting level will merge inherited defaults in addition to their own.
|
||||
#
|
||||
# NOTE: Each nesting level will merge inherited defaults in addition to their own.
|
||||
#
|
||||
# class Post < ActiveRecord::Base
|
||||
# with_options if: :persisted?, length: { minimum: 50 } do
|
||||
# validates :content, if: -> { content.present? }
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# The code is equivalent to:
|
||||
#
|
||||
# validates :content, length: { minimum: 50 }, if: -> { content.present? }
|
||||
#
|
||||
# Hence the inherited default for `if` key is ignored.
|
||||
#
|
||||
def with_options(options, &block)
|
||||
option_merger = ActiveSupport::OptionMerger.new(self, options)
|
||||
block.arity.zero? ? option_merger.instance_eval(&block) : block.call(option_merger)
|
||||
|
|
Loading…
Reference in a new issue