Created
April 30, 2009 10:17
-
-
Save schmurfy/104385 to your computer and use it in GitHub Desktop.
Ruby Tips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# convert to integer: 12, 0x03 | |
# raise an error if the string contains something other that a valid number | |
n = Integer(string) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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