Created
March 1, 2009 23:24
-
-
Save sstephenson/72527 to your computer and use it in GitHub Desktop.
This file contains 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
def extract_options_from(arguments) | |
arguments.values_at *(indexes_for(arguments) - argument_indexes_for(arguments)) | |
end | |
def extract_arguments_from(arguments) | |
arguments.values_at *argument_indexes_for(arguments) | |
end | |
def indexes_for(arguments) | |
(0...arguments.length).to_a | |
end | |
def argument_indexes_for(arguments) | |
returning indexes_for(arguments) do |indexes| | |
arguments.each_with_index do |argument, index| | |
case argument | |
when /^--.+=/ | |
indexes[index, 2] = [nil, nil] | |
when /^-(-$)?/ | |
indexes[index] = nil | |
break if $1 | |
end | |
end | |
end.compact | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment