Is it ruby convention for all files to be in a module with the folder structure (similar to java packages)?
For example, if I have a file structure that looks like
lib/people/utils
would the files in here have the module structure such as:
module People
module Utils
# some functionality for People::Utils
end
end
The reason I ask is because I’ve been reading through some rails code, and there seem to be several files that are in a file structure like this, but don’t have any module declarations.
I’m guessing this would be so you could use the utility function without having to include People::Utils.
Is there a convention in ruby as to when modules should be used and when they shouldn’t?
It’s generally a good idea to put classes and files in a structure like that, because it will make it easier for people to map the name of the class to its definition.
But it can make sense not to do this (ultimately you structure your code however you like). I’ve occasionally done it when there were lots of small classes all dealing with the same thing, I put them together.
And it can make sense to have a file which does not define a module or class, e.g. a configuration file, or a binary, or a bootstrapping file (file which loads up all the other ones).