Skip to content

Instantly share code, notes, and snippets.

@knowtheory
Created June 28, 2010 11:51
Show Gist options
  • Select an option

  • Save knowtheory/455743 to your computer and use it in GitHub Desktop.

Select an option

Save knowtheory/455743 to your computer and use it in GitHub Desktop.
module RequireTree
@@require_tree = {:system => $".dup}
def require(string)
@current = $".dup
result = super(string)
@@require_tree[string] = $" - @current
result
end
def reload(matcher)
if matcher.is_a? String
paths = @@require_tree[matcher]
keys = [matcher]
elsif matcher.is_a? Regexp
keys = @@require_tree.keys.select{ |k| k =~ matcher}
paths = keys.map{ |k| @@require_tree[k] }.flatten
else
raise ArgumentError
end
paths.each{ |p| $".delete(p) }
keys.map{ |k| [k, (require k)] }
end
def self.file_tree
@@require_tree
end
end
include RequireTree
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment