-
-
Save disolovyov/599111 to your computer and use it in GitHub Desktop.
Autoloading with namespaces
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
# Extremely simple autoloading implementation | |
class Module | |
alias const_missing_without_autoloading const_missing | |
def const_missing(const) | |
path = "#{name.gsub('::', '/')}/#{const}" | |
path.gsub!(/([a-z\d])([A-Z])/,'\1_\2') | |
require path.downcase | |
const_defined?(const) ? const_get(const) : super | |
rescue LoadError => error | |
warn(error.message) | |
super | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment