aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorZachary Scott <e@zzak.io>2014-10-18 12:43:24 -0700
committerZachary Scott <e@zzak.io>2014-10-18 12:43:24 -0700
commitf7059cdd36c196abda881ec85645e2532a7c5a6a (patch)
tree5f63de316bc5de03edb31e4699d137607d3857bc /activesupport
parentc33b5e841b54357c1589942dc70192ab0b51fc1e (diff)
parentf5a906005b06326f4afb75b5f8577437f7a24654 (diff)
downloadrails-f7059cdd36c196abda881ec85645e2532a7c5a6a.tar.gz
rails-f7059cdd36c196abda881ec85645e2532a7c5a6a.tar.bz2
rails-f7059cdd36c196abda881ec85645e2532a7c5a6a.zip
Merge pull request #17034 from pramod-sharma/master
[ci skip] Add Doc of with_options for the case when inherited default options and original options have same keys
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/object/with_options.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/with_options.rb b/activesupport/lib/active_support/core_ext/object/with_options.rb
index 42e87c4424..7d38e1d134 100644
--- a/activesupport/lib/active_support/core_ext/object/with_options.rb
+++ b/activesupport/lib/active_support/core_ext/object/with_options.rb
@@ -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)