htatche
htatche

Reputation: 693

Define several modules in a single file

Is it possible to merge multiple module definitions in a single file and avoid possible clashes with Rails autoloading ?

Thanks !

Upvotes: 2

Views: 1379

Answers (1)

Aleksei Matiushkin
Aleksei Matiushkin

Reputation: 121000

I am not sure I understood how this would help “to avoid possible clashes with Rails autoloading”, but the answer is “yes”: one might define as many modules, classes, constants and whatever is defineable in the single file.

Ruby has no restriction on the relation between file names and modules/classes names. One might define modules A1 and A2 in file b.rb. Standard lib/namespace/class_name.rb convetion is the convention only, as soon as file is required, it’s content is being loaded.

Upvotes: 1

Related Questions