Skip to content

Instantly share code, notes, and snippets.

@sstephenson
Created March 1, 2009 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sstephenson/72527 to your computer and use it in GitHub Desktop.
Save sstephenson/72527 to your computer and use it in GitHub Desktop.
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