aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVipul A M <vipulnsward@gmail.com>2017-03-17 12:20:22 +0530
committerGitHub <noreply@github.com>2017-03-17 12:20:22 +0530
commitd5c32f87119b87e36e06aefd538b733857d7b2ef (patch)
tree4c63987e6575dbfeddf7fbcf10760176a3f7fd33
parentb9c399de22aa84c94bb6b2edf6f8e88b88ac5f4a (diff)
parent4ac5f90e92fb8c803a98189a91431f7a2e42c6a7 (diff)
downloadrails-d5c32f87119b87e36e06aefd538b733857d7b2ef.tar.gz
rails-d5c32f87119b87e36e06aefd538b733857d7b2ef.tar.bz2
rails-d5c32f87119b87e36e06aefd538b733857d7b2ef.zip
Merge pull request #28445 from denniszelada/feature-documentation-with_options
Add documentation to use with_options anywhere in the same class [ci
-rw-r--r--activesupport/lib/active_support/core_ext/object/with_options.rb11
1 files changed, 11 insertions, 0 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 cf39b1d312..4afb20ebfd 100644
--- a/activesupport/lib/active_support/core_ext/object/with_options.rb
+++ b/activesupport/lib/active_support/core_ext/object/with_options.rb
@@ -62,6 +62,17 @@ class Object
#
# Hence the inherited default for `if` key is ignored.
#
+ # NOTE: You cannot call class methods implicitly inside of with_options,
+ # refer the methods using the class name instead, like so:
+ #
+ # class Phone < ActiveRecord::Base
+ # enum phone_number_type: [home: 0, office: 1, mobile: 2]
+ #
+ # with_options presence: true do
+ # validates :phone_number_type, inclusion: { in: Phone.phone_number_types.keys }
+ # end
+ # end
+ #
def with_options(options, &block)
option_merger = ActiveSupport::OptionMerger.new(self, options)
block.arity.zero? ? option_merger.instance_eval(&block) : block.call(option_merger)