Class: Slop::BoolOption
Overview
Cast the option argument to true or false. Override default_value to default to false instead of nil. This option type does not expect an argument. However, the API supports value being passed. This is to ensure it can capture an explicit false value
Direct Known Subclasses
Constant Summary
Constants inherited from Option
Instance Attribute Summary collapse
-
#explicit_value ⇒ Object
Returns the value of attribute explicit_value.
Attributes inherited from Option
#block, #config, #count, #desc, #flags
Instance Method Summary collapse
- #call(value) ⇒ Object
- #default_value ⇒ Object
- #expects_argument? ⇒ Boolean
- #force_false? ⇒ Boolean
- #value ⇒ Object
Methods inherited from Option
#ensure_call, #finish, #flag, #help?, #initialize, #key, #null?, #reset, #suppress_errors?, #tail, #tail?, #to_s
Constructor Details
This class inherits a constructor from Slop::Option
Instance Attribute Details
#explicit_value ⇒ Object
Returns the value of attribute explicit_value.
15 16 17 |
# File 'lib/slop/types.rb', line 15 def explicit_value @explicit_value end |
Instance Method Details
#call(value) ⇒ Object
17 18 19 20 |
# File 'lib/slop/types.rb', line 17 def call(value) self.explicit_value = value !force_false? end |
#default_value ⇒ Object
34 35 36 |
# File 'lib/slop/types.rb', line 34 def default_value config[:default] || false end |
#expects_argument? ⇒ Boolean
38 39 40 |
# File 'lib/slop/types.rb', line 38 def expects_argument? false end |
#force_false? ⇒ Boolean
30 31 32 |
# File 'lib/slop/types.rb', line 30 def force_false? explicit_value == false end |
#value ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/slop/types.rb', line 22 def value if force_false? false else super end end |