Class: Clio::Usage::Argument
- Inherits:
-
Object
- Object
- Clio::Usage::Argument
- Defined in:
- lib/clio/usage/argument.rb
Overview
Usage Argument
Instance Attribute Summary collapse
-
#help(string = nil) ⇒ Object
readonly
Specify help text for argument.
-
#name ⇒ Object
readonly
attr :parent.
-
#splat(true_or_false = nil) ⇒ Object
readonly
Returns the value of attribute splat.
-
#type(string = nil) ⇒ Object
readonly
Specify the type of the argument.
Instance Method Summary collapse
-
#initialize(name, &block) ⇒ Argument
constructor
New Argument.
- #initialize_copy(o) ⇒ Object
- #inspect ⇒ Object
-
#key ⇒ Object
Same as
name
but given as a symbol. - #to_s ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Argument
New Argument. def initialize(name, parent=nil, &block)
16 17 18 19 20 21 22 23 |
# File 'lib/clio/usage/argument.rb', line 16 def initialize(name, &block) @name = name.to_s @type = name.upcase #@parent = parent @splat = false @help = '' instance_eval(&block) if block end |
Instance Attribute Details
#help(string = nil) ⇒ Object (readonly)
Specify help text for argument.
57 58 59 |
# File 'lib/clio/usage/argument.rb', line 57 def help @help end |
#name ⇒ Object (readonly)
attr :parent
9 10 11 |
# File 'lib/clio/usage/argument.rb', line 9 def name @name end |
#splat(true_or_false = nil) ⇒ Object (readonly)
Returns the value of attribute splat.
12 13 14 |
# File 'lib/clio/usage/argument.rb', line 12 def splat @splat end |
#type(string = nil) ⇒ Object (readonly)
Specify the type of the argument. This is an arbitrary description of the type. The value given is converted to uppercase.
arg.type('file')
arg.type #=> 'FILE'
44 45 46 |
# File 'lib/clio/usage/argument.rb', line 44 def type @type end |
Instance Method Details
#initialize_copy(o) ⇒ Object
26 27 28 29 30 |
# File 'lib/clio/usage/argument.rb', line 26 def initialize_copy(o) @name = o.name.dup @type = o.type.dup @help = o.help.dup end |
#inspect ⇒ Object
72 73 74 75 76 77 |
# File 'lib/clio/usage/argument.rb', line 72 def inspect s = "<#{name}" s << ":#{type.inspect}" if type s << ">" s end |
#key ⇒ Object
Same as name
but given as a symbol.
33 34 35 |
# File 'lib/clio/usage/argument.rb', line 33 def key name.to_sym end |
#to_s ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/clio/usage/argument.rb', line 62 def to_s if name.upcase == type s = "<#{name}" else s = "<#{name}:#{type}" end s << (splat ? "...>" : ">") s end |