class ConventionalExtensions::Loader

def extension_path_for(extension)

def extension_path_for(extension)
  @path_format % extension.to_s
end

def extension_paths

def extension_paths
  Dir.glob extension_path_for("*")
end

def initialize(klass, path)

def initialize(klass, path)
  @loaded, @klass, @matcher = Set.new, klass, /\s*class #{klass.name}/
  @path_format = File.join path.sub(/\.rb$/, "/extensions/%s.rb")
end

def load(*extensions)

def load(*extensions)
  paths = extensions.empty? ? extension_paths : extensions.map { extension_path_for _1 }
  paths.each { load_one _1 }
end

def load_one(extension)

def load_one(extension)
  if @loaded.add?(extension)
    if contents = File.read(extension) and contents.match?(@matcher)
      ::Kernel.load extension
    else
      @klass.class_eval contents, extension, 0
    end
  end
end