module Atchoum # Reloads the application whenever the script is changed. # Inspired by _why's Camping Reloader # http://code.whytheluckystiff.net/svn/camping/trunk/lib/camping/reloader.rb class Reloader attr_reader :class_name, :instance def initialize(script) @script = File.expand_path(script) @class_name = script.scan(/(\w+).rb$/)[0].first.capitalize.gsub(/_(\w)/) { $1.to_s.upcase } end def find_class @klass = Object.const_get(Object.constants.grep(/^#{@class_name}$/i)[0]) rescue nil @instance = @klass.new end def unload_class Object.send :remove_const, @klass.name if @klass @klass = nil @instance = nil end # Reload the script def reload # TODO maybe check for timestamp ? unload_class load @script find_class end end end