Skip to content

Instantly share code, notes, and snippets.

@disolovyov
Forked from rkh/simple_autoloader.rb
Created September 27, 2010 14:26
Show Gist options
  • Save disolovyov/599111 to your computer and use it in GitHub Desktop.
Save disolovyov/599111 to your computer and use it in GitHub Desktop.
Autoloading with namespaces
# 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