diff options
author | Lee Jarvis <ljjarvis@gmail.com> | 2015-02-04 08:32:22 +0000 |
---|---|---|
committer | Lee Jarvis <ljjarvis@gmail.com> | 2015-02-04 08:32:22 +0000 |
commit | 877946b0a16607bec39dcd437d30e7bb0afa4600 (patch) | |
tree | bfb57ecb39825599c72093193fae260087f6d5b6 /lib | |
parent | 67866658053bb22997e3fb1ffc64605b6ab15027 (diff) | |
download | slop-877946b0a16607bec39dcd437d30e7bb0afa4600.tar.gz |
Add explicit value setter to Result class
closes #162
Diffstat (limited to 'lib')
-rw-r--r-- | lib/slop/result.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/slop/result.rb b/lib/slop/result.rb index 8cdfa12..eaad707 100644 --- a/lib/slop/result.rb +++ b/lib/slop/result.rb @@ -20,6 +20,17 @@ module Slop end alias get [] + # Set the value for an option. Raises an ArgumentError if the option + # does not exist. + def []=(flag, value) + if o = option(flag) + o.value = value + else + raise ArgumentError, "no option with flag `#{flag}'" + end + end + alias set []= + # Returns an Option if it exists. Ignores any prefixed hyphens. def option(flag) cleaned = -> (f) { f.to_s.sub(/\A--?/, '') } |