Skip to content

Instantly share code, notes, and snippets.

@buren buren/snippets.cson
Created Aug 1, 2018

Embed
What would you like to do?
Atom snippet - Ruby optparse template
'.source.ruby':
'Insert Ruby optparser':
'prefix': 'optparse'
'body':
'''
require 'optparse'
options = {}
OptionParser.new do |parser|
parser.banner = 'Usage: ${1:script_name} --help'
parser.default_argv = ARGV
parser.on('--${2:arg0}=val0', String, '') do |string|
options[:${2:arg0}] = string
end
parser.on('--${3:arg1}=first,second', Array, '') do |array|
options[:${3:arg1}] = array
end
parser.on('--[no-]${4:arg2}', '') do |boolean|
options[:${4:arg2}] = boolean
end
parser.on('-h', '--help', 'How to use') do
puts parser
exit
end
end.parse!
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.