aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorDennis Zelada <dennis.zelada@modomoto.de>2017-03-14 12:42:41 +0100
committerDennis Zelada <dennis.zelada@modomoto.de>2017-03-16 18:15:36 +0100
commit4ac5f90e92fb8c803a98189a91431f7a2e42c6a7 (patch)
tree1b01f659f68c1839e71b0d7d40ca2859a9afcbda /activesupport
parent039380e3eeb24ed17f1824183b94638f0cfff747 (diff)
downloadrails-4ac5f90e92fb8c803a98189a91431f7a2e42c6a7.tar.gz
rails-4ac5f90e92fb8c803a98189a91431f7a2e42c6a7.tar.bz2
rails-4ac5f90e92fb8c803a98189a91431f7a2e42c6a7.zip
Add documentation to use with_options in the same class [ci skip]
Diffstat (limited to 'activesupport')
-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)