Skip to content

Instantly share code, notes, and snippets.

@jtpaasch
Created August 12, 2015 11:26
Show Gist options
  • Save jtpaasch/b9c2cae29393cbfa5cb9 to your computer and use it in GitHub Desktop.
Save jtpaasch/b9c2cae29393cbfa5cb9 to your computer and use it in GitHub Desktop.
A simple Ruby argument parsing loop.
#!/usr/bin/env ruby
if ARGV.empty?
puts "No arguments provided."
end
until ARGV.empty? do
case ARGV[0]
when '-q'
ARGV.shift
value = ARGV[0]
puts "-q = #{value}"
ARGV.shift
when /-h|--help/
puts "Help"
ARGV.shift
else
puts 'Stopping'
break
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment