Skip to content

Instantly share code, notes, and snippets.

@cshirley
Created November 29, 2018 17:56
Show Gist options
  • Select an option

  • Save cshirley/8a0f8d5dd9fc030b3c4d7914f7ec8028 to your computer and use it in GitHub Desktop.

Select an option

Save cshirley/8a0f8d5dd9fc030b3c4d7914f7ec8028 to your computer and use it in GitHub Desktop.
OptionParser for Rake task
task :add_args do
args = ARGV[2..-1]
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: rake test:check_args [options]"
opts.on("-o", "--one ARG", Integer) { |num1| options[:num1] = num1 }
opts.on("-t", "--two ARG", Integer) { |num2| options[:num2] = num2 }
end.parse!(args)
puts options[:num1].to_i + options[:num2].to_i
exit
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment