Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uninitialized constant error, with fix #3

Closed
RoryO opened this issue Jun 14, 2010 · 1 comment
Closed

Uninitialized constant error, with fix #3

RoryO opened this issue Jun 14, 2010 · 1 comment

Comments

@RoryO
Copy link

RoryO commented Jun 14, 2010

On some systems, running twurl can can cause the error:

rory@ubuntu:~/Documents/twurl$ ./bin/twurl
/home/rory/Documents/twurl/lib/twurl/request_controller.rb:2:in `<module:Twurl>':uninitialized constant Twurl::AbstractCommandController (NameError)

This smells like a file isn't being loaded, so looking at twurl.rb, the culprit is this:

library_files = Dir[File.join(File.dirname(__FILE__), "/twurl/**/*.rb")]
library_files.each do |file|
    require file
end

The reason this is a problem is the Dir[] construction doesn't guarantee any sort of order as it relies on the OS for ordering. We can see this by changing it to:

library_files = Dir[File.join(File.dirname(__FILE__), "/twurl/**/*.rb")]
puts "The first file loaded is: " + library_files.first
exit

Which outputs (on my system)
The first file loaded is: /home/rory/Documents/twurl/lib/twurl/request_controller.rb

Since request_controller subclasses AbstractCommandController, it fails because that file hasn't been loaded yet. There's two ways out of this: either specifying the requires by hand in order or setting up autoloads. (Rails dances around the issue by messing with autoload and using ActiveSupport for class symbol -> file name mapping)

I fixed this in my fork using autoloads and sent a pull request.

@sferik
Copy link
Contributor

sferik commented Sep 30, 2010

Looks like this issue is fixed in master at a1a196a and released in v0.6.2.

@RoryO RoryO closed this as completed Jul 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants