In general, you will have one class per file and one folder per module namespace, so for instance:
MyGem
becomes lib/my_gem.rb
MyGem::Widget
becomes lib/my_gem/widget.rb
MyGem::Widgets::FooBar
becomes lib/my_gem/widgets/foo_bar.rb
When a developer wants to use your library, they should be able to do so (in almost all cases) by making a single require statement that is identical to the gem name.
That means that in the root file you need
to make any additional require statements necessary for your gem to
function. So if I have
a MyGem
module,
a MyGem::Widget
class, and a
MyGem::Widgets::FooBar
class,
the lib/my_gem.rb
file in my gem might
look like this:
require 'external_library' # require any external dependencies module MyGem # it is best to declare the base module at the top end require 'my_gem/version' # created by Bundler require 'my_gem/widget' require 'my_gem/widgets/foo_bar'By requiring all of the files necessary for your gem to run in the base file you make it easier for developers to use your library.
Casiano Rodriguez León 2015-01-07