From: "R.. Kumar" Date: 2010-06-11T18:10:59+09:00 Subject: Re: creating a gem structure for command line program R.. Kumar wrote: > Thomas Sawyer wrote: > >> >> 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. > > This (#2) is roughly how the "cheat" gem does it. I think it will take > me a few minutes to change it. Thanks a lot. Are there any naming conventions here that have to be followed. Assume project and gem is named foo. 1. bin/foo - does foo have to be the project/gem name 2. lib/foo/main.rb - does main.rb have to be foo.rb Why i ask is because, typically main.rb would contain a class named "Foo". 3. lib/foo.rb - currently I've got an empty file. -- Posted via http://www.ruby-forum.com/.