diff options
author | Lee Jarvis <ljjarvis@gmail.com> | 2014-12-17 09:28:56 +0000 |
---|---|---|
committer | Lee Jarvis <ljjarvis@gmail.com> | 2014-12-17 09:28:56 +0000 |
commit | e131477f00db7b85645aef87dd69e042d12b2e5c (patch) | |
tree | e15e91a51d86e1b30c415dfee99399ad259fd7fd /lib | |
parent | 8c4a3e281338c133c6a5c6b342ecd889c6ea07c3 (diff) | |
download | slop-e131477f00db7b85645aef87dd69e042d12b2e5c.tar.gz |
Document Option
Diffstat (limited to 'lib')
-rw-r--r-- | lib/slop/option.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/slop/option.rb b/lib/slop/option.rb index 85d7cb7..870c518 100644 --- a/lib/slop/option.rb +++ b/lib/slop/option.rb @@ -16,6 +16,8 @@ module Slop reset end + # Reset the option count and value. Used when calling .reset + # on the Parser. def reset @value = nil @count = 0 @@ -36,6 +38,8 @@ module Slop block.call(@value) if block.respond_to?(:call) end + # This method is called immediately when an option is found. + # Override it in sub-classes. def call(_value) raise NotImplementedError, "you must override the `call' method for option #{self.class}" @@ -59,30 +63,37 @@ module Slop false end + # Returns the value for this option. Falls back to the default (or nil). def value @value || default_value end + # Returns the default value for this option (default is nil). def default_value config[:default] end + # Returns true if we should ignore errors that cause exceptions to be raised. def suppress_errors? config[:suppress_errors] end + # Returns all flags joined by a comma. Used by the help string. def flag flags.join(", ") end + # Returns the last key as a symbol. Used in Options.to_hash. def key (config[:key] || flags.last.sub(/\A--?/, '')).to_sym end + # Returns true if this option should be displayed in help text. def help? config[:help] end + # Returns the help text for this option (flags and description). def to_s(offset: 0) "%-#{offset}s %s" % [flag, desc] end |