Class: Clamp::Parameter::Definition
- Inherits:
-
Attribute::Definition
- Object
- Attribute::Definition
- Clamp::Parameter::Definition
- Defined in:
- lib/clamp/parameter/definition.rb
Overview
Represents an parameter of a Clamp::Command class.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from Attribute::Definition
#description, #environment_variable
Instance Method Summary collapse
- #consume(arguments) ⇒ Object
- #help_lhs ⇒ Object
- #inheritable? ⇒ Boolean
-
#initialize(name, description, options = {}) ⇒ Definition
constructor
A new instance of Definition.
Methods inherited from Attribute::Definition
#append_method, #attribute_name, #default_method, #default_value, #help, #help_rhs, #hidden?, #ivar_name, #multivalued?, #of, #option_missing_message, #read_method, #required?, #write_method
Constructor Details
#initialize(name, description, options = {}) ⇒ Definition
Returns a new instance of Definition.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/clamp/parameter/definition.rb', line 12 def initialize(name, description, = {}) @name = name @description = description super() @multivalued = (@name =~ ELLIPSIS_SUFFIX) @required = .fetch(:required) do (@name !~ OPTIONAL) end @inheritable = .fetch(:inheritable, true) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/clamp/parameter/definition.rb', line 23 def name @name end |
Instance Method Details
#consume(arguments) ⇒ Object
33 34 35 36 |
# File 'lib/clamp/parameter/definition.rb', line 33 def consume(arguments) raise ArgumentError, Clamp.(:no_value_provided) if required? && arguments.empty? arguments.shift(multivalued? ? arguments.length : 1) end |
#help_lhs ⇒ Object
29 30 31 |
# File 'lib/clamp/parameter/definition.rb', line 29 def help_lhs name end |
#inheritable? ⇒ Boolean
25 26 27 |
# File 'lib/clamp/parameter/definition.rb', line 25 def inheritable? @inheritable end |