Skip to content

Instantly share code, notes, and snippets.

@rkh
Created August 18, 2010 06:57
Show Gist options
  • Save rkh/533770 to your computer and use it in GitHub Desktop.
Save rkh/533770 to your computer and use it in GitHub Desktop.
# 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