Skip to content

Instantly share code, notes, and snippets.

@rklemme
Created April 6, 2011 12:51
Show Gist options
  • Save rklemme/905589 to your computer and use it in GitHub Desktop.
Save rklemme/905589 to your computer and use it in GitHub Desktop.
Example usage of OptionParser with type safety.
require 'optparse'
first = last = nil
OptionParser.new do |opts|
opts.on '-s', '--start=LINE', Integer, 'Start line' do |v|
first = v
end
opts.on '-e', '--end=LINE', Integer, 'End line' do |v|
first = v
end
end.parse! ARGV
p first, first.class, last, last.class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment