Class: Argy::Option
Instance Attribute Summary collapse
-
#aliases ⇒ Object
readonly
Returns the value of attribute aliases.
Attributes inherited from Parameter
Instance Method Summary collapse
-
#initialize(*args, aliases: [], **opts) ⇒ Option
constructor
A new instance of Option.
- #label ⇒ Object
- #to_option_parser ⇒ Object
Methods inherited from Parameter
#coerce, #required?, #validate
Constructor Details
#initialize(*args, aliases: [], **opts) ⇒ Option
Returns a new instance of Option.
7 8 9 10 |
# File 'lib/argy/option.rb', line 7 def initialize(*args, aliases: [], **opts) super(*args, **opts) @aliases = aliases end |
Instance Attribute Details
#aliases ⇒ Object (readonly)
Returns the value of attribute aliases.
5 6 7 |
# File 'lib/argy/option.rb', line 5 def aliases @aliases end |
Instance Method Details
#label ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/argy/option.rb', line 12 def label case type when :boolean "--[no-]#{name.to_s.tr("_", "-")}" else "--#{name.to_s.tr("_", "-")}" end end |
#to_option_parser ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/argy/option.rb', line 21 def to_option_parser = [] << aliases.join(" ") unless aliases.empty? case type when :boolean << label else << "#{label}=#{name.to_s.upcase}" << "#{label} #{name.to_s.upcase}" end << desc if desc end |