diff options
author | okuramasafumi <masafumi.o1988@gmail.com> | 2019-04-16 10:55:47 +0900 |
---|---|---|
committer | okuramasafumi <masafumi.o1988@gmail.com> | 2019-04-17 18:41:53 +0900 |
commit | 8dcce7021fbadb344d3b04243f8e01017a0baab8 (patch) | |
tree | a9953d0c0f9e930630a164a600d4de1fdb413e32 /activesupport/lib | |
parent | f37e6c0e5814b5d2bc6c3038659c713c172bedbd (diff) | |
download | rails-8dcce7021fbadb344d3b04243f8e01017a0baab8.tar.gz rails-8dcce7021fbadb344d3b04243f8e01017a0baab8.tar.bz2 rails-8dcce7021fbadb344d3b04243f8e01017a0baab8.zip |
Add documentations to AS::Concern#included and #class_methods
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/concern.rb | 23 |
1 files changed, 23 insertions, 0 deletions
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) : |