Skip to content

Instantly share code, notes, and snippets.

@philsturgeon
Created February 14, 2013 22:20
Show Gist options
  • Save philsturgeon/4956941 to your computer and use it in GitHub Desktop.
Save philsturgeon/4956941 to your computer and use it in GitHub Desktop.
Autoload through folder structures and whatnot
def Object.const_missing(name)
@looked_for ||= {}
str_name = name.to_s
raise "Class not found: #{name}" if @looked_for[str_name]
@looked_for[str_name] = 1
file = str_name.gsub!(/(.)([A-Z])/,'\1/\2') && downcase!
loaded_parts = []
file.split('/').each do |part|
this_file = loaded_parts.push(part).join('/')
require "woe/#{this_file}.rb"
end
klass = const_get(name)
return klass if klass
raise "Class not found: #{name}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment