Class: Ame::Class
- Inherits:
-
Object
- Object
- Ame::Class
- Defined in:
- lib/ame-1.0/class.rb
Overview
Direct Known Subclasses
Class Method Summary collapse
-
.basename(basename = nil) ⇒ String
Sets or returns, depending on if BASENAME is nil or not, the basename of the receiver.
-
.call(method, arguments = nil, options = nil) ⇒ self
Call METHOD with ARGUMENTS and OPTIONS on a new instance of the receiver.
-
.description(description = nil) ⇒ String
Sets the DESCRIPTION of the method about to be defined, or returns it if DESCRIPTION is nil.
-
.fullname ⇒ String
The full name of the space-separated concatenation of the basenames of the receiver and its Class.parents.
-
.help(help = nil) ⇒ #method, ...
Sets the HELP object to use for displaying usage information, or returns it if HELP is nil.
-
.methods ⇒ Methods
The methods defined on the receiver.
-
.process(method, arguments = []) ⇒ self
Process ARGUMENTS as a list of options and arguments, then call METHOD with the results of this processing on a new instance of the receiver.
Class Method Details
.basename(basename = nil) ⇒ String
Sets or returns, depending on if BASENAME is nil or not, the basename of the receiver. The basename is the downcased last component of the double-colon-separated name of the class with all camel-cased sub-words separated by dashes.
387 388 389 390 391 |
# File 'lib/ame-1.0/class.rb', line 387 def basename(basename = nil) @basename = basename if basename return @basename if defined? @basename name.split('::').last.scan(/[[:upper:]][[:lower:]]*/).join('-').downcase end |
.call(method, arguments = nil, options = nil) ⇒ self
Call METHOD with ARGUMENTS and OPTIONS on a new instance of the receiver. This method catches AbortProcessing. Options are arguments that begin with ‘-` or `–`. If options_must_precede_arguments has been called on the receiver, then options must precede arguments. Either way, a `–` argument will always end the processing of options and begin processing of arguments instead.
42 43 44 45 46 47 |
# File 'lib/ame-1.0/class.rb', line 42 def call(method, arguments = nil, = nil) catch Ame::AbortProcessing do methods[method].call new, arguments, end self end |
.description(description = nil) ⇒ String
Sets the DESCRIPTION of the method about to be defined, or returns it if DESCRIPTION is nil. The description is used in help output and similar circumstances. A description can only be given to a public method, as only public methods can be used as Ame methods.
59 60 61 62 |
# File 'lib/ame-1.0/class.rb', line 59 def description(description = nil) return method.description(description) if description defined?(@description) ? @description : '' end |
.fullname ⇒ String
Returns The full name of the space-separated concatenation of the basenames of the receiver and its parents.
399 400 401 402 403 404 405 406 407 |
# File 'lib/ame-1.0/class.rb', line 399 def fullname [].tap{ |names| klass = self until klass.nil? or klass.basename.empty? names << klass.basename klass = klass.parent end }.reverse.join(' ') end |
.help(help = nil) ⇒ #method, ...
Sets the HELP object to use for displaying usage information, or returns it if HELP is nil. The default is to delegate the request to the parent.
372 373 374 375 |
# File 'lib/ame-1.0/class.rb', line 372 def help(help = nil) return @help = help if help @help ||= Ame::Help::Delegate.new(parent.help) end |
.methods ⇒ Methods
Returns The methods defined on the receiver.
411 412 413 |
# File 'lib/ame-1.0/class.rb', line 411 def methods @methods ||= Ame::Methods.new end |
.process(method, arguments = []) ⇒ self
Process ARGUMENTS as a list of options and arguments, then call METHOD with the results of this processing on a new instance of the receiver. This method catches AbortProcessing. Options are arguments that begin with ‘-` or `–`. If options_must_precede_arguments has been called on the receiver, then options must precede arguments. Either way, a `–` argument will always end the processing of options and begin processing of arguments instead.
22 23 24 25 26 27 |
# File 'lib/ame-1.0/class.rb', line 22 def process(method, arguments = []) catch Ame::AbortProcessing do methods[method].process new, arguments end self end |