diff options
author | Lee Jarvis <ljjarvis@gmail.com> | 2014-12-30 14:56:56 +0000 |
---|---|---|
committer | Lee Jarvis <ljjarvis@gmail.com> | 2014-12-30 14:56:56 +0000 |
commit | 9963f1b6893d3100b88a7c96a2b805356c0bc8c8 (patch) | |
tree | 5a462ae744f3f4820e4e8ae6cbdbc2ad031c974a /lib | |
parent | 1966798a229ad21940ed44fe190fa13e451f4960 (diff) | |
download | slop-9963f1b6893d3100b88a7c96a2b805356c0bc8c8.tar.gz |
Add some basic type docs
Diffstat (limited to 'lib')
-rw-r--r-- | lib/slop/types.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/slop/types.rb b/lib/slop/types.rb index cc10e63..8bc7f65 100644 --- a/lib/slop/types.rb +++ b/lib/slop/types.rb @@ -1,10 +1,14 @@ module Slop + # Cast the option argument to a String. class StringOption < Option def call(value) value.to_s end end + # 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. class BoolOption < Option def call(_value) true @@ -20,6 +24,7 @@ module Slop end BooleanOption = BoolOption + # Cast the option argument to an Integer. class IntegerOption < Option def call(value) value =~ /\A\d+\z/ && value.to_i @@ -27,6 +32,7 @@ module Slop end IntOption = IntegerOption + # Cast the option argument to a Float. class FloatOption < Option def call(value) # TODO: scientific notation, etc. @@ -34,6 +40,8 @@ module Slop end end + # Collect multiple items into a single Array. Support + # arguments separated by commas or multiple occurences. class ArrayOption < Option def call(value) @value ||= [] @@ -49,7 +57,8 @@ module Slop end end - # an option that discards the return value + # An option that discards the return value, inherits from Bool + # since it does not expect an argument. class NullOption < BoolOption def null? true |