Class is required but cannot be accessed

Viewed 210

I have a very odd error I cannot wrap my head around.

Basically, I have this class in my lib folder:

# lib/api/amazon.rb
module API
  class Amazon
    ...
  end
end

When I want to use it somewhere, I require it:

require 'api/amazon'
API::Amazon.do_stuff

This works initially but after a while it breaks and raises NameError: uninitialized constant API::Amazon. When I debug this and try to require the file again when the error is raised, it returns false, indicating that the file was already loaded. I can also see it in $" (this list of loaded files). Why can I then not access API::Amazon?

Note: I added "API" as an acronym to ActiveSupport::Inflector which is why I don't have to use "Api":

# config/initializers/inflections.rb
ActiveSupport::Inflector.inflections do |inflect|
  inflect.acronym 'API'
end

EDIT:

I tried ::API::Amazon.do_stuff as well, same result.

2 Answers
Related