Class: Recheck::Optimist::ShortNames
- Inherits:
-
Object
- Object
- Recheck::Optimist::ShortNames
- Defined in:
- lib/recheck/vendor/optimist.rb
Constant Summary collapse
- INVALID_ARG_REGEX =
:nodoc:
/[\d-]/
Instance Attribute Summary collapse
-
#auto ⇒ Object
readonly
Returns the value of attribute auto.
-
#chars ⇒ Object
readonly
Returns the value of attribute chars.
Instance Method Summary collapse
- #add(values) ⇒ Object
-
#initialize ⇒ ShortNames
constructor
A new instance of ShortNames.
Constructor Details
#initialize ⇒ ShortNames
746 747 748 749 |
# File 'lib/recheck/vendor/optimist.rb', line 746 def initialize @chars = [] @auto = true end |
Instance Attribute Details
#auto ⇒ Object (readonly)
Returns the value of attribute auto.
751 752 753 |
# File 'lib/recheck/vendor/optimist.rb', line 751 def auto @auto end |
#chars ⇒ Object (readonly)
Returns the value of attribute chars.
751 752 753 |
# File 'lib/recheck/vendor/optimist.rb', line 751 def chars @chars end |
Instance Method Details
#add(values) ⇒ Object
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 |
# File 'lib/recheck/vendor/optimist.rb', line 753 def add(values) values = [values] unless values.is_a?(Array) # box the value values = values.compact if values.include?(:none) if values.size == 1 @auto = false return end raise ArgumentError, "Cannot use :none with any other values in short option: #{values.inspect}" end values.each do |val| strval = val.to_s sopt = case strval when /^-(.)$/ then $1 when /^.$/ then strval else raise ArgumentError, "invalid short option name '#{val.inspect}'" end if INVALID_ARG_REGEX.match?(sopt) raise ArgumentError, "short option name '#{sopt}' can't be a number or a dash" end @chars << sopt end end |