Cyril Duchon-Doris Cyril Duchon-Doris - 7 days ago 4x
Ruby Question

Rails autoloading fully capitalized name like API

I have some structure

  • /lib/dokuwiki.rb

  • /lib/dokuwiki/exception.rb

  • /lib/dokuwiki/api/connection.rb


require 'dokuwiki/exception.rb'

module Dokuwiki


module Dokuwiki
module API
class Connection

Now, when I try to call
from a controller (without any
), Rails default constants autoloading fails. I believe this is because the
module should have a folder named
instead of
but that's ugly.

Of course I could require 'dokuwiki/api/connection.rb', in the main '/lib/dokuwiki.rb' file, but then it wouldn't reload this class automatically (which is kinda annoying in a dev context)

What can I do to keep the nice
folder name and be able to do some live modifications to
without having to restart my server ?


There's a file called config/initializers/inflections.rb.

Add in it

ActiveSupport::Inflector.inflections do |inflect|
  inflect.acronym 'API' 

and the API namespace will be available as a directory called api