From 8dcce7021fbadb344d3b04243f8e01017a0baab8 Mon Sep 17 00:00:00 2001 From: okuramasafumi Date: Tue, 16 Apr 2019 10:55:47 +0900 Subject: 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 @@ module ActiveSupport 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 @@ module ActiveSupport 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) : -- cgit v1.2.3