summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLee Jarvis <ljjarvis@gmail.com>2014-12-17 09:34:34 +0000
committerLee Jarvis <ljjarvis@gmail.com>2014-12-17 09:34:34 +0000
commit18e223d53a3faa248b4e78d58d4808d6995aae54 (patch)
tree7d9306eb86074cf8cc105d22bdeaba833dbe9250 /lib
parente131477f00db7b85645aef87dd69e042d12b2e5c (diff)
downloadslop-18e223d53a3faa248b4e78d58d4808d6995aae54.tar.gz
Document Parser
Diffstat (limited to 'lib')
-rw-r--r--lib/slop/parser.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/slop/parser.rb b/lib/slop/parser.rb
index 6e17d48..85a9428 100644
--- a/lib/slop/parser.rb
+++ b/lib/slop/parser.rb
@@ -9,13 +9,22 @@ module Slop
reset
end
- # Reset the parser, useful to use the same instance
- # to parse a second time without duplicating state.
+ # Reset the parser, useful to use the same instance to parse a second
+ # time without duplicating state.
def reset
@options.each(&:reset)
self
end
+ # Traverse `strings` and process options one by one. Anything after
+ # `--` is ignored. If a flag includes a equals (=) it will be split
+ # so that `flag, argument = s.split('=')`.
+ #
+ # The `call` method will be executed immediately for each option found.
+ # Once all options have been executed, any found options will have
+ # the `finish` method called on them.
+ #
+ # Returns a Slop::Result.
def parse(strings)
pairs = strings.each_cons(2).to_a
pairs << [strings.last, nil]
@@ -35,10 +44,12 @@ module Slop
end
end
+ # Returns an Array of Option instances that were used.
def used_options
options.select { |o| o.count > 0 }
end
+ # Returns an Array of Option instances that were not used.
def unused_options
options.to_a - used_options
end