Class: Optimist::LongNames
- Inherits:
-
Object
- Object
- Optimist::LongNames
- Defined in:
- lib/optimist.rb
Instance Method Summary collapse
-
#initialize ⇒ LongNames
constructor
A new instance of LongNames.
-
#long ⇒ Object
long specified with :long has precedence over the true-name.
- #make_valid(lopt) ⇒ Object
-
#names ⇒ Object
all valid names, including alts.
- #set(name, lopt, alts) ⇒ Object
Constructor Details
#initialize ⇒ LongNames
Returns a new instance of LongNames.
694 695 696 697 698 |
# File 'lib/optimist.rb', line 694 def initialize @truename = nil @long = nil @alts = [] end |
Instance Method Details
#long ⇒ Object
long specified with :long has precedence over the true-name
718 |
# File 'lib/optimist.rb', line 718 def long ; @long || @truename ; end |
#make_valid(lopt) ⇒ Object
700 701 702 703 704 705 706 707 |
# File 'lib/optimist.rb', line 700 def make_valid(lopt) return nil if lopt.nil? case lopt.to_s when /^--([^-].*)$/ then $1 when /^[^-]/ then lopt.to_s else raise ArgumentError, "invalid long option name #{lopt.inspect}" end end |
#names ⇒ Object
all valid names, including alts
721 722 723 |
# File 'lib/optimist.rb', line 721 def names [long] + @alts end |
#set(name, lopt, alts) ⇒ Object
709 710 711 712 713 714 715 |
# File 'lib/optimist.rb', line 709 def set(name, lopt, alts) @truename = name lopt = lopt ? lopt.to_s : name.to_s.gsub("_", "-") @long = make_valid(lopt) alts = [alts] unless alts.is_a?(Array) # box the value @alts = alts.map { |alt| make_valid(alt) }.compact end |