# CREDIT George Moschovitis

class Module

  # A useful macro for dynamic modules.
  #--
  # FIXME: quick and easy implementation, should
  # come up with something better. The name 
  # sucks too.
  #++
  def on_included(code)
    tag = caller[0].split(' ').first.split(/\/|\\/).last.gsub(/:|\.|\(|\)/, '_')
    old = "__included_#{tag}"
    module_eval %{
      class << self
        alias_method :#{old}, :included
        def included(base)
          #{old}(base)
          #{code}
        end
      end
    }
  end
end

=begin Testing

module M
  on_included %{
    puts 'hello'
  }
end

module Q
  on_included %{
    puts 'world'
  }
  on_included %{
    puts 'it works'
  }
end

class C 
  include M
  include Q
end

=end
