diff options
author | Lee Jarvis <ljjarvis@gmail.com> | 2014-11-19 13:23:12 +0000 |
---|---|---|
committer | Lee Jarvis <ljjarvis@gmail.com> | 2014-11-19 13:23:12 +0000 |
commit | ff8ad326fed2099c412dc7a31cefdf52f2221b66 (patch) | |
tree | aa3966935b8da80f8832e6f07daaa0e07a4cb014 /lib | |
parent | e3901588e3e767ffd6a08e32b535d15c5032351a (diff) | |
download | slop-ff8ad326fed2099c412dc7a31cefdf52f2221b66.tar.gz |
Support method_missing checks for used options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/slop/result.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/slop/result.rb b/lib/slop/result.rb index 0d0a3ab..f43ddef 100644 --- a/lib/slop/result.rb +++ b/lib/slop/result.rb @@ -18,6 +18,7 @@ module Slop def [](flag) (o = option(flag)) && o.value end + alias get [] # Returns an Option if it exists. Ignores any prefixed hyphens. def option(flag) @@ -27,6 +28,18 @@ module Slop end end + def method_missing(name, *args, &block) + if respond_to_missing?(name) + (o = option(name.to_s.chomp("?"))) && used_options.include?(o) + else + super + end + end + + def respond_to_missing?(name, include_private = false) + name.to_s.end_with?("?") || super + end + def used_options parser.used_options end |