Created
October 26, 2009 16:28
-
-
Save aereal/218780 to your computer and use it in GitHub Desktop.
Python's 'import' like it
This file contains 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
def import(feature, as={}) | |
ret = require feature | |
self.class.instance_eval do | |
as.each do |(orig, dest)| | |
c = const_get(orig) | |
remove_const(orig) if const_defined?(orig) | |
const_set(dest, c) | |
end | |
end unless as.empty? | |
ret | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment