Use bundle gem gemname
to generate your gem's doc structure:
.
├── Gemfile
├── LICENSE.txt
├── README.md
├── Rakefile
├── gemname.gemspec
├── lib
│ ├── gemname
│ │ └── version.rb
│ └── gemname.rb
Add a bin directory and put your executable there.
.
├── bin
│ └── gemname
Presumably, your executable will require
your gem, but then if you run it like ruby bin/gemname
, require
will look for an installed gem, not the one in your lib directory.
To address this, add the following before any require
statements in your executable:
lib = File.expand_path('../../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
It took me way too long to figure this out, until I realized what that little piece of code was doing at the top of the generated .gemspec. Sigh.
Improvements welcome!
So, just noticed this bit here:
Even though I pulled this technique directly from the .gemspec Bundler generated for me, I wonder if this is still not the best idea after all...