Florent2/Watts-Strogatz-model-network-generator — Issue #1: bin/run_experiment.rb
Author: semmons99
Created: 2012-01-25 13:16:11+00:00
State: open

Assuming you decide to package this library up as a gem, your current implementation of `bin/run_experiment.rb` will not work correctly. When a gem is installed all of it's executable files are copied into `RUBY_DIR/bin`. This means that `require_relative "../lib/wsmodel"` is no longer the correct relative path.

To combat this, we instead use `require "wsmodel"`, loading the gem from it's installed location. However, this now poses a problem when testing the executable; it can no longer can find the code. There's a simple fix. When testing your executable, run it by doing the following `ruby -Ilib bin/run_experiment.rb`. The `-Ilib` adds `lib/` to the `LOAD_PATH`. Similar to what rubygems is doing when we require a gem.

There are also two naming problems with this executable. First, when creating an executable, we omit the extension (`.rb`) and rely on the hash-bang on the first line of the file to describe how to run the file. This is standard practice which helps guarantee our executable will work on *nix and Windows systems. Second, our executable should be named the same as our library (`wsmodel`). This avoids executable name collisions between gems.