Class: Slop::BoolOption

Inherits:
Option
  • Object
show all
Defined in:
lib/slop/types.rb

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

NullOption

Constant Summary

Constants inherited from Option

Option::DEFAULT_CONFIG

Instance Attribute Summary collapse

Attributes inherited from Option

#block, #config, #count, #desc, #flags

Instance Method Summary collapse

Methods inherited from Option

#ensure_call, #finish, #flag, #help?, #initialize, #key, #null?, #required?, #reset, #suppress_errors?, #tail, #tail?, #to_s, #underscore_flags?

Constructor Details

This class inherits a constructor from Slop::Option

Instance Attribute Details

#explicit_valueObject

Returns the value of attribute explicit_value.



22
23
24
# File 'lib/slop/types.rb', line 22

def explicit_value
  @explicit_value
end

Instance Method Details

#call(value) ⇒ Object



24
25
26
27
# File 'lib/slop/types.rb', line 24

def call(value)
  self.explicit_value = value
  !force_false?
end

#default_valueObject



41
42
43
# File 'lib/slop/types.rb', line 41

def default_value
  config[:default] || false
end

#expects_argument?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/slop/types.rb', line 45

def expects_argument?
  false
end

#force_false?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/slop/types.rb', line 37

def force_false?
  explicit_value == false
end

#valueObject



29
30
31
32
33
34
35
# File 'lib/slop/types.rb', line 29

def value
  if force_false?
    false
  else
    super
  end
end