Gist にだけあったものをサルベージして Qiita にも。
clap-loader.rb
module Matome
@@clapLoader = nil
def self.clap(dir=nil)
if @@clapLoader then
@@clapLoader.reload
else
@@clapLoader = ClapLoader.new dir
end
end
class ClapLoader
def initialize(dir)
@own = __FILE__
@dir = dir.split('/')[0..-2].join('/')
@mtimes = {}
reload
end
def reload
$LOADED_FEATURES.each{|f|
if f != @own && f.start_with?(@dir) then
File::Stat.new(f).mtime.tap { |mtimeOnFS|
@mtimes[f].tap { |mtimeOnCache|
if ! mtimeOnCache then
@mtimes[f] = mtimeOnFS
elsif mtimeOnFS > mtimeOnCache then
warn("LOADING: %s" % f)
load f
@mtimes[f] = File::Stat.new(f).mtime
end
}
} rescue warn('skip ... %s' % f)
end
}
end
end
end
__END__
main.rb
require 'matome/clap-loader'
require 'matome/something-great'
Matome.clap __FILE__
Matome.SomethingGreat
Matome.clap
Qiita と Gist の連携は、先に Gist に書いちゃだめで、Qiita の記事を投稿したときにコード部分が Gist に載るようにするしかないのね。