Open pruett opened 10 years ago
So no need for require_relative?
this could be false, but i see less use of require_relative
when compared to relative
. i'm not sure if one is preferred over the other, but i tend to stick with require
. you may need to update your load path in order to properly require
files. a line like this is very common:
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
This is a fairly cryptic (in my opinion) way of saying "add ../lib
to the load path so i can can call require
on files from this directory"
That said, if require_relative
is working and require
isn't, i would stick to what's working. This is more of a housekeeping/structure opinion.
Here is an example of this type of structure from the warden repo: https://github.com/hassox/warden/tree/master/lib
The pattern that @pruett suggests is very much close to the rubygems pattern of loading code. This will help you if you do go the route of packaging this into a gem.
As far as resources on rubygems, this is an oldie but a goodie
:+1: for @kylemac's resources. these are really good
Feel free to weigh in guys, but I feel like cleaning up the
/lib
folder would help with readability/maintainablity as you extend the library. Instead of listing all of the.rb
files within/lib
, a common convention is to have your main file, probably namedsunnyside.rb
along with a folder that contains all your library files, so a folder named/sunnyside
. Thesunnyside.rb
file would contain much of therequire
ing of files, setup, etc. that refer to your source files, now under the/lib/sunnyside
directoryAgain this is mostly for readablility and housecleaning, but could help in organizing not only your files, but your code. I would start by organizing your files in a way that relates to your
menu
file. Also, following this convention andrequire
ing all files withinsunnyside.rb
means you can justrequire /path/to/sunnyside.rb
in yourmenu
file