Method: OptparsePlus::Main#main
- Defined in:
- lib/optparse_plus/main.rb
#main(&block) ⇒ Object
Declare the main method for your app. This allows you to specify the general logic of your app at the top of your bin file, but can rely on any methods or other code that you define later.
For example, suppose you want to process a set of files, but wish to determine that list from another method to keep your code clean.
#!/usr/bin/env ruby -w
require 'optparse_plus'
include OptparsePlus::Main
main do
files_to_process.each do |file|
# process file
end
end
def files_to_process
# return list of files
end
go!
The block can accept any parameters, and unparsed arguments from the command line will be passed.
Note: #go! will modify ARGV so any unparsed arguments that you do not declare as arguments to #main will essentially be unavailable. I consider this a bug, and it should be changed/fixed in a future version.
To run this method, call #go!
116 117 118 |
# File 'lib/optparse_plus/main.rb', line 116 def main(&block) @main_block = block end |