Created
November 29, 2012 18:07
-
-
Save burtlo/4170839 to your computer and use it in GitHub Desktop.
Working around autoload. When forcing source files to be loaded is important.
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
def safely_load(mod,constant) | |
mod.const_get constant | |
rescue NameError | |
puts "#{mod}::#{constant} was not defined autoloadable, but caused NameError" | |
rescue LoadError | |
puts "#{mod}::#{constant} was not loadable" | |
end | |
def preload(mod) | |
mod.constants.each do |constant| | |
puts "Autoloading Constant: #{mod}::#{constant}" | |
if mod.autoload? constant | |
safely_load mod, constant | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment