Skip to content

Instantly share code, notes, and snippets.

@schmurfy
Created April 30, 2009 10:17
Show Gist options
  • Save schmurfy/104385 to your computer and use it in GitHub Desktop.
Save schmurfy/104385 to your computer and use it in GitHub Desktop.
Ruby Tips
# convert to integer: 12, 0x03
# raise an error if the string contains something other that a valid number
n = Integer(string)
require 'optparse'
options = Hash.new
options_parser = OptionParser.new do |opts|
opts.on("-o", "--option [ARG]", String, "Optionnal argument") do |opt|
app['option'] = opt
end
opts.on("-o", "--option ARG", String, "Required argument") do |opt|
app['option'] = opt
end
end
begin
options_parser.parse!(ARGV)
rescue OptionParser::ParseError => e
puts e
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment