As we all know, the common structure of rubygem assumes presence of lib
directory. I noticed, that generally in this directory are two items: gem_name.rb
and gem_name/
directory. The gem_name/
directory hold main sources of project. It is heart of application. So, the question is about gem_name.rb
file. What does it stand for?
Asked
Active
Viewed 227 times
1

kyrylo
- 1,691
- 1
- 15
- 22
2 Answers
2
The reason it's structured like that is if you had files other than gem_name.rb
in the lib/
directory (say another_file_name.rb
), you'd be liable to cause problems if there was a gem with the name another_file_name
and someone did require another_file_name
- it'd load your file, rather than the other gem's file.
If your code is small enough it can all fit into gem_name.rb
, then put it there, otherwise put it into gem_name/other_file_name.rb
.

Andrew Grimm
- 78,473
- 57
- 200
- 338
1
Typically that just requires everything from the gem_name/
directory that's needed. It's used to keep all the require
s in a central location and separate from the actual code

Andrew Marshall
- 95,083
- 20
- 220
- 214
-
Take a look for https://github.com/wycats/thor/blob/master/lib/thor.rb I see only one require. – kyrylo Mar 07 '11 at 00:38
-
*shrugs*. Doesn't mean it's the rule. The `gem_name.rb` file is what gets required, so it must require everything else. In that case they require `thor/base`, which then requires a lot more. – Andrew Marshall Mar 07 '11 at 00:41