Skip to content

Instantly share code, notes, and snippets.

@unau
Last active September 16, 2017 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unau/94efd42bed93f31c1ec50491b168adf0 to your computer and use it in GitHub Desktop.
Save unau/94efd42bed93f31c1ec50491b168adf0 to your computer and use it in GitHub Desktop.
自分は SketchUp の Ruby コンソールで使うんだけど、開発中にいろいろスクリプトをいじったとして、Ruby コンソールで Matome.clap とやると更新のあったファイルだけリロードしてくれるようなもの
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__
require 'matome/clap-loader'
require 'matome/something-great'
Matome.clap __FILE__
Matome.SomethingGreat
Matome.clap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment