Skip to content

Instantly share code, notes, and snippets.

@burtlo
Created November 29, 2012 18:07
Show Gist options
  • Save burtlo/4170839 to your computer and use it in GitHub Desktop.
Save burtlo/4170839 to your computer and use it in GitHub Desktop.
Working around autoload. When forcing source files to be loaded is important.
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