Created
November 29, 2018 17:56
-
-
Save cshirley/8a0f8d5dd9fc030b3c4d7914f7ec8028 to your computer and use it in GitHub Desktop.
OptionParser for Rake task
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
| 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