Skip to content

Instantly share code, notes, and snippets.

@tkawa
Last active December 21, 2015 10:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tkawa/6292031 to your computer and use it in GitHub Desktop.
included do |mod| ... end としてincludeされたモジュールの情報を使いたい。
module ActiveSupport
module Concern
def append_features(base)
if base.instance_variable_defined?("@_dependencies")
base.instance_variable_get("@_dependencies") << self
return false
else
return false if base < self
@_dependencies.each { |dep| base.send(:include, dep) }
super
base.extend const_get("ClassMethods") if const_defined?("ClassMethods")
if instance_variable_defined?("@_included_block")
if @_included_block.is_a? Array
base.class_exec(@_included_block[0], &@_included_block[1]) # give module as first argument
else
base.class_exec(&@_included_block)
end
end
end
end
def included(base = nil, &block)
if base.nil?
@_included_block = [self, block] # store module (= self)
else
super
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment