Skip to content

Instantly share code, notes, and snippets.

@burtlo
Created October 31, 2012 09:15
Show Gist options
  • Save burtlo/3986007 to your computer and use it in GitHub Desktop.
Save burtlo/3986007 to your computer and use it in GitHub Desktop.
Looking at ways to provide auto-reloading to an application outside of the Rails space.
class A
def hello ; puts "hello" ; end
def goodbye ; puts "goodbye" ; end
end
class A
def silence ; puts "silence" ; end
end
require 'active_support'
require 'active_support/dependencies'
require 'open3'
include ActiveSupport::Dependencies
hook!
watcher = WatchStack.new
watcher.watch_namespaces([ Object ])
require './a_test'
watcher.new_constants.each do |constant|
puts "Marking clas: #{constant} unloadable"
unloadable constant
end
output, status = Open3.capture2e("ruby b_test.rb")
valid_code = (status == 0)
puts "Success? #{status}"
# We only wnat to clear and load the code if the code is valid ruby code
if valid_code
clear
require_or_load('./b_test')
else
puts "*" * 80
puts "There was an error in your code:"
puts output
puts "*" * 80
end
[ :hello, :goodbye, :silence ].each do |method|
puts "A##{method} #{A.instance_methods.include?(method)}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment