Created
February 14, 2013 22:20
-
-
Save philsturgeon/4956941 to your computer and use it in GitHub Desktop.
Autoload through folder structures and whatnot
This file contains 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 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