Created
June 28, 2010 11:51
-
-
Save knowtheory/455743 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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