Class: Ame::Method::Undefined
- Inherits:
-
Object
- Object
- Ame::Method::Undefined
- Defined in:
- lib/ame-1.0/method/undefined.rb
Overview
A Ame::Method in its undefined state. This class is used to construct the method before it gets defined, setting up a description, specifying that options_must_precede_arguments, adding flags, toggles, switches, options, multioptions, arguments, optional arguments, splats, spluses, and finally defining it.
Instance Method Summary collapse
-
#argument(name, type, description) {|?| ... } ⇒ self
Delegates Class.argument to Arguments::Undefined#argument.
-
#arguments? ⇒ Boolean
True if any arguments have been defined on the receiver.
-
#define(ruby_name) ⇒ Method
The method RUBY_NAME after adding a “help” flag that’ll display help via Class.help#method and raise AbortAllProcessing.
-
#description(description = nil) ⇒ String
Sets the DESCRIPTION of the method, or returns it if DESCRIPTION is nil.
-
#flag(short, long, default, description) {|?| ... } ⇒ self
Delegates Class.flag to Options::Undefined#flag.
-
#initialize(klass) ⇒ Undefined
constructor
Sets up an as yet undefined method on KLASS.
-
#multioption(short, long, argument, type, description) {|?| ... } ⇒ self
Delegates Class.multioption to Options::Undefined#multioption.
-
#option(short, long, argument, default, description) {|?| ... } ⇒ self
Delegates Class.option to Options::Undefined#option.
-
#option?(option) ⇒ Boolean
True if OPTION has been defined on the receiver.
-
#optional(name, default, description) {|?| ... } ⇒ self
Delegates Class.argument to Arguments::Undefined#optional or Arguments::Optional#optional.
-
#options_must_precede_arguments ⇒ self
Forces options to the method to precede any arguments to be processed correctly.
-
#splat(name, type, description) {|?| ... } ⇒ self
Delegates Class.argument to Arguments::Undefined#splat.
-
#splus(name, type, description) {|?| ... } ⇒ self
Delegates Class.argument to Arguments::Undefined#splus.
-
#switch(short, long, argument, default, argument_default, description) {|?| ... } ⇒ self
Delegates Class.switch to Options::Undefined#switch.
-
#toggle(short, long, default, description) {|?| ... } ⇒ self
Delegates Class.toggle to Options::Undefined#toggle.
-
#valid? ⇒ Boolean
True if a description has been defined on the receiver.
Constructor Details
#initialize(klass) ⇒ Undefined
Sets up an as yet undefined method on KLASS.
13 14 15 16 17 18 |
# File 'lib/ame-1.0/method/undefined.rb', line 13 def initialize(klass) @class = klass @description = nil = Ame::Options::Undefined.new @arguments = Ame::Arguments::Undefined.new end |
Instance Method Details
#argument(name, type, description) {|?| ... } ⇒ self
Delegates Class.argument to Arguments::Undefined#argument.
109 110 111 112 |
# File 'lib/ame-1.0/method/undefined.rb', line 109 def argument(name, type, description, &validate) @arguments.argument(name, type, description, &validate) self end |
#arguments? ⇒ Boolean
Returns True if any arguments have been defined on the receiver.
176 177 178 |
# File 'lib/ame-1.0/method/undefined.rb', line 176 def arguments? not @arguments.empty? end |
#define(ruby_name) ⇒ Method
Returns The method RUBY_NAME after adding a “help” flag that’ll display help via Class.help#method and raise AbortAllProcessing.
161 162 163 164 165 166 167 |
# File 'lib/ame-1.0/method/undefined.rb', line 161 def define(ruby_name) flag '', 'help', nil, 'Display help for this method' do @class.help.method @class.methods[Ame::Method.name(ruby_name)] throw Ame::AbortAllProcessing end unless .include? 'help' Ame::Method.new(ruby_name, @class, @description, .define, @arguments.define) end |
#description(description = nil) ⇒ String
Sets the DESCRIPTION of the method, or returns it if DESCRIPTION is nil. The description is used in help output and similar circumstances.
25 26 27 28 29 |
# File 'lib/ame-1.0/method/undefined.rb', line 25 def description(description = nil) return @description unless description @description = description self end |
#flag(short, long, default, description) {|?| ... } ⇒ self
Delegates Class.flag to Options::Undefined#flag.
47 48 49 50 |
# File 'lib/ame-1.0/method/undefined.rb', line 47 def flag(short, long, default, description, &validate) .flag short, long, default, description, &validate self end |
#multioption(short, long, argument, type, description) {|?| ... } ⇒ self
Delegates Class.multioption to Options::Undefined#multioption.
95 96 97 98 |
# File 'lib/ame-1.0/method/undefined.rb', line 95 def multioption(short, long, argument, type, description, &validate) .multioption short, long, argument, type, description, &validate self end |
#option(short, long, argument, default, description) {|?| ... } ⇒ self
Delegates Class.option to Options::Undefined#option.
83 84 85 86 |
# File 'lib/ame-1.0/method/undefined.rb', line 83 def option(short, long, argument, default, description, &validate) .option short, long, argument, default, description, &validate self end |
#option?(option) ⇒ Boolean
Returns True if OPTION has been defined on the receiver.
171 172 173 |
# File 'lib/ame-1.0/method/undefined.rb', line 171 def option?(option) .include? option end |
#optional(name, default, description) {|?| ... } ⇒ self
Delegates Class.argument to Arguments::Undefined#optional or Arguments::Optional#optional.
124 125 126 127 |
# File 'lib/ame-1.0/method/undefined.rb', line 124 def optional(name, default, description, &validate) @arguments = @arguments.optional(name, default, description, &validate) self end |
#options_must_precede_arguments ⇒ self
Forces options to the method to precede any arguments to be processed correctly.
35 36 37 38 |
# File 'lib/ame-1.0/method/undefined.rb', line 35 def . self end |
#splat(name, type, description) {|?| ... } ⇒ self
Delegates Class.argument to Arguments::Undefined#splat.
138 139 140 141 |
# File 'lib/ame-1.0/method/undefined.rb', line 138 def splat(name, type, description, &validate) @arguments = @arguments.splat(name, type, description, &validate) self end |
#splus(name, type, description) {|?| ... } ⇒ self
Delegates Class.argument to Arguments::Undefined#splus.
153 154 155 156 |
# File 'lib/ame-1.0/method/undefined.rb', line 153 def splus(name, type, description, &validate) @arguments = @arguments.splus(name, type, description, &validate) self end |
#switch(short, long, argument, default, argument_default, description) {|?| ... } ⇒ self
Delegates Class.switch to Options::Undefined#switch.
71 72 73 74 |
# File 'lib/ame-1.0/method/undefined.rb', line 71 def switch(short, long, argument, default, argument_default, description, &validate) .switch short, long, argument, default, argument_default, description, &validate self end |
#toggle(short, long, default, description) {|?| ... } ⇒ self
Delegates Class.toggle to Options::Undefined#toggle.
59 60 61 62 |
# File 'lib/ame-1.0/method/undefined.rb', line 59 def toggle(short, long, default, description, &validate) .toggle short, long, default, description, &validate self end |
#valid? ⇒ Boolean
Returns True if a description has been defined on the receiver.
181 182 183 |
# File 'lib/ame-1.0/method/undefined.rb', line 181 def valid? not description.nil? end |