From: Intransition Date: 2010-06-11T17:47:11+09:00 Subject: Re: creating a gem structure for command line program On Jun 11, 3:55 am, "R.. Kumar" wrote: > Rein Henrichs wrote: > > On 2010-06-11 00:15:24 -0700, R.. Kumar said: > > >> thx for help. > > > Put your executable in bin/ and any supporting code in lib/ > > > Rubygems will take care of distributing your executable in the way you > > mentioned, you don't have to do anything except add it to the gemspec. > > Thanks. I was looking at some other gems such as cheat and maruku, and I > was going to model my command line progs on maruku. > > Last question, what about the lib/.rb file. Usually it just > contains some "require" statements. In my case, the file in bin > (.rb) already contains the includes. Do i keep an empty file, > or just put the includes in there anyway. > > Thanks again for the immed response. First, there's two overarching ways to go about this: 1) put exe code in a bin/ file 2) only put bootstrap code in bin/ to an lib/ file. Either way is fine. I tend to use #2 because it has some small advantages --all code is in one place, relative requires are safe within lib//. To give you an example, a bin/foo might look like: #!/usr/bin/env ruby require 'foo/main.rb' Foo.main(*ARGV) And that's all. Then in lib/foo/main.rb you would define a Foo.main method to handle command-line invocation. And remember the advantages of encapsulation. Maruku's executables lack this, so they cannot be reused, inherited, unit tested, etc.