Class: Ame::Arguments::Optional
- Defined in:
- lib/ame-1.0/arguments/optional.rb
Overview
The arguments to a method in its undefined state where at least one optional argument has been defined and only further #optional or #splat arguments are allowed.
Instance Method Summary collapse
- #argument(name, type, description, &validate) ⇒ Object
-
#initialize(arguments, optional) ⇒ Optional
constructor
A new instance of Optional.
-
#optional(name, default, description) {|?| ... } ⇒ self
Adds a new Optional argument to the receiver.
- #splus(name, default, description, &validate) ⇒ Object
Methods inherited from Undefined
Constructor Details
#initialize(arguments, optional) ⇒ Optional
Returns a new instance of Optional.
9 10 11 |
# File 'lib/ame-1.0/arguments/optional.rb', line 9 def initialize(arguments, optional) @arguments, @optional = arguments + [optional], optional end |
Instance Method Details
#argument(name, type, description, &validate) ⇒ Object
14 15 16 17 |
# File 'lib/ame-1.0/arguments/optional.rb', line 14 def argument(name, type, description, &validate) raise ArgumentError, "argument '%s', … may not follow optional '%s', …" % [name, @optional.name] end |
#optional(name, default, description) {|?| ... } ⇒ self
Adds a new Ame::Arguments::Optional argument to the receiver.
31 32 33 |
# File 'lib/ame-1.0/arguments/optional.rb', line 31 def optional(name, default, description, &validate) self << Ame::Optional.new(name, default, description, &validate) end |
#splus(name, default, description, &validate) ⇒ Object
20 21 22 23 |
# File 'lib/ame-1.0/arguments/optional.rb', line 20 def splus(name, default, description, &validate) raise ArgumentError, "splus '%s', … may not follow optional '%s', …" % [name, @optional.name] end |