From 4ac5f90e92fb8c803a98189a91431f7a2e42c6a7 Mon Sep 17 00:00:00 2001 From: Dennis Zelada Date: Tue, 14 Mar 2017 12:42:41 +0100 Subject: Add documentation to use with_options in the same class [ci skip] --- .../lib/active_support/core_ext/object/with_options.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'activesupport/lib') 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) -- cgit v1.2.3