module ActiveSupport::Concern

def self.extended(base) # :nodoc:

:nodoc:
def self.extended(base) # :nodoc:
  base.instance_variable_set(:@_dependencies, [])
end

def append_features(base) # :nodoc:

:nodoc:
def append_features(base) # :nodoc:
  if base.instance_variable_defined?(:@_dependencies)
    base.instance_variable_get(:@_dependencies) << self
    false
  else
    return false if base < self
    @_dependencies.each { |dep| base.include(dep) }
    super
    base.extend const_get(:ClassMethods) if const_defined?(:ClassMethods)
    base.class_eval(&@_included_block) if instance_variable_defined?(:@_included_block)
  end
end

def class_methods(&class_methods_module_definition)

Buzz.bar # => private method 'bar' called for Buzz:Class(NoMethodError)
Buzz.foo # => "foo"

end
include Example
class Buzz

end
end
def bar; puts 'bar'; end
private

def foo; puts 'foo'; end
class_methods do

extend ActiveSupport::Concern
module Example

You can define private class methods as well.
Define class methods from given block.
def class_methods(&class_methods_module_definition)
  mod = const_defined?(:ClassMethods, false) ?
    const_get(:ClassMethods) :
    const_set(:ClassMethods, Module.new)
  mod.module_eval(&class_methods_module_definition)
end

def included(base = nil, &block)

When you define more than one +included+ block, it raises an exception.
so that you can write class macros here.
Evaluate given block in context of base class,
def included(base = nil, &block)
  if base.nil?
    if instance_variable_defined?(:@_included_block)
      if @_included_block.source_location != block.source_location
        raise MultipleIncludedBlocks
      end
    else
      @_included_block = block
    end
  else
    super
  end
end

def prepend_features(base) # :nodoc:

:nodoc:
def prepend_features(base) # :nodoc:
  if base.instance_variable_defined?(:@_dependencies)
    base.instance_variable_get(:@_dependencies).unshift self
    false
  else
    return false if base < self
    @_dependencies.each { |dep| base.prepend(dep) }
    super
    base.singleton_class.prepend const_get(:ClassMethods) if const_defined?(:ClassMethods)
    base.class_eval(&@_prepended_block) if instance_variable_defined?(:@_prepended_block)
  end
end

def prepended(base = nil, &block)

When you define more than one +prepended+ block, it raises an exception.
so that you can write class macros here.
Evaluate given block in context of base class,
def prepended(base = nil, &block)
  if base.nil?
    if instance_variable_defined?(:@_prepended_block)
      if @_prepended_block.source_location != block.source_location
        raise MultiplePrependBlocks
      end
    else
      @_prepended_block = block
    end
  else
    super
  end
end