From f37e6c0e5814b5d2bc6c3038659c713c172bedbd Mon Sep 17 00:00:00 2001 From: okuramasafumi Date: Sun, 7 Apr 2019 11:47:20 +0900 Subject: [PATCH 1/2] Add `:nodoc` to ActiveSupport::Concern#append_features --- activesupport/lib/active_support/concern.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/concern.rb b/activesupport/lib/active_support/concern.rb index 5d356a0ab6..1b997d53c8 100644 --- a/activesupport/lib/active_support/concern.rb +++ b/activesupport/lib/active_support/concern.rb @@ -110,7 +110,7 @@ def self.extended(base) #:nodoc: base.instance_variable_set(:@_dependencies, []) end - def append_features(base) + def append_features(base) #:nodoc: if base.instance_variable_defined?(:@_dependencies) base.instance_variable_get(:@_dependencies) << self false From 8dcce7021fbadb344d3b04243f8e01017a0baab8 Mon Sep 17 00:00:00 2001 From: okuramasafumi Date: Tue, 16 Apr 2019 10:55:47 +0900 Subject: [PATCH 2/2] Add documentations to AS::Concern#included and #class_methods --- activesupport/lib/active_support/concern.rb | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/activesupport/lib/active_support/concern.rb b/activesupport/lib/active_support/concern.rb index 1b997d53c8..708c445031 100644 --- a/activesupport/lib/active_support/concern.rb +++ b/activesupport/lib/active_support/concern.rb @@ -123,6 +123,9 @@ def append_features(base) #:nodoc: end end + # Evaluate given block in context of base class, + # so that you can write class macros here. + # When you define more than one +included+ block, it raises an exception. def included(base = nil, &block) if base.nil? if instance_variable_defined?(:@_included_block) @@ -137,6 +140,26 @@ def included(base = nil, &block) end end + # Define class methods from given block. + # You can define private class methods as well. + # + # module Example + # extend ActiveSupport::Concern + # + # class_methods do + # def foo; puts 'foo'; end + # + # private + # def bar; puts 'bar'; end + # end + # end + # + # class Buzz + # include Example + # end + # + # Buzz.foo # => "foo" + # Buzz.bar # => private method 'bar' called for Buzz:Class(NoMethodError) def class_methods(&class_methods_module_definition) mod = const_defined?(:ClassMethods, false) ? const_get(:ClassMethods) :