diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2014-02-23 12:06:18 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2014-02-23 12:06:23 -0700 |
commit | b16c36e688970df2f96f793a759365b248b582ad (patch) | |
tree | cf8f4e85a6ee1a4aab0caca6c70d843fbc852b57 /activesupport/lib | |
parent | 96759cf6c6a17053abb6a2b7cd87cdbd5a8420ba (diff) | |
download | rails-b16c36e688970df2f96f793a759365b248b582ad.tar.gz rails-b16c36e688970df2f96f793a759365b248b582ad.tar.bz2 rails-b16c36e688970df2f96f793a759365b248b582ad.zip |
Introduce Concern#class_methods and Kernel#concern
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/concern.rb | 10 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/kernel.rb | 3 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/kernel/concern.rb | 10 |
3 files changed, 21 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/concern.rb b/activesupport/lib/active_support/concern.rb index b796d01dfd..9d5cee54e3 100644 --- a/activesupport/lib/active_support/concern.rb +++ b/activesupport/lib/active_support/concern.rb @@ -26,7 +26,7 @@ module ActiveSupport # scope :disabled, -> { where(disabled: true) } # end # - # module ClassMethods + # class_methods do # ... # end # end @@ -130,5 +130,13 @@ module ActiveSupport super end end + + def class_methods(&class_methods_module_definition) + mod = const_defined?(:ClassMethods) ? + const_get(:ClassMethods) : + const_set(:ClassMethods, Module.new) + + mod.module_eval(&class_methods_module_definition) + end end end diff --git a/activesupport/lib/active_support/core_ext/kernel.rb b/activesupport/lib/active_support/core_ext/kernel.rb index 0275f4c037..aa19aed43b 100644 --- a/activesupport/lib/active_support/core_ext/kernel.rb +++ b/activesupport/lib/active_support/core_ext/kernel.rb @@ -1,4 +1,5 @@ -require 'active_support/core_ext/kernel/reporting' require 'active_support/core_ext/kernel/agnostics' +require 'active_support/core_ext/kernel/concern' require 'active_support/core_ext/kernel/debugger' +require 'active_support/core_ext/kernel/reporting' require 'active_support/core_ext/kernel/singleton_class' diff --git a/activesupport/lib/active_support/core_ext/kernel/concern.rb b/activesupport/lib/active_support/core_ext/kernel/concern.rb new file mode 100644 index 0000000000..c200a78d36 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/kernel/concern.rb @@ -0,0 +1,10 @@ +require 'active_support/core_ext/module/concerning' + +module Kernel + # A shortcut to define a toplevel concern, not within a module. + # + # See ActiveSupport::CoreExt::Module::Concerning for more. + def concern(topic, &module_definition) + Object.concern topic, &module_definition + end +end |