From: Eric Hodel Date: 2006-12-19T17:36:43+09:00 Subject: Re: Strategies for writing Ruby applications to be easily distributed with RubyGems On Dec 18, 2006, at 23:49, Zev Blut wrote: > On Tue, 19 Dec 2006 16:31:48 +0900, Eric Hodel > wrote: >> On Dec 18, 2006, at 22:34, Zev Blut wrote: > >>> I would like to know is are there any better or commonly followed >>> ways >>> of writing executables that work with RubyGems and other >>> installation >>> programs such as setup.rb ? >> >> My executables typically consist of three lines: >> >> #!/usr/local/bin/ruby -w >> require 'some_file' >> SomeFile.run >> >> Where SomeFile::run is something like: >> >> class SomeFile >> def self.run(args = ARGV) >> options = process_args args >> new(option[:foo]).run >> end >> end > > Yes that is a good way to solve this problem. > >>> 2) >>> I was reading through the Programming Ruby book and found a part >>> that >>> showed how to use rdoc to create usage messages. I figured this >>> might >>> be better than my normal technique so I used it in Saikuro. This >>> has >>> caused a number of problems actually. >> >> What does this technique look like? I'm not familiar with it. > > http://ruby-doc.org/stdlib/libdoc/rdoc/rdoc/classes/RDoc.html#M001338 > > It is something like this: > > ------------- > #!/usr/bin/env ruby > # == Usage > # Some stuff on how to use a program. > # More stuff > > require 'rdoc/usage' > > RDoc.usage Since RDoc.usage uses #caller to figure out which file to read you should be able to combine RDoc.usage with my method above, and the usage will live in the library file. -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net I LIT YOUR GEM ON FIRE!