class Ame::Method
A method in its defined state. @api developer
Attributes
@return [Arguments] The arguments of the receiver
@return [String] The description of the receiver
@return [Options] The options of the receiver
Public Class Methods
@param [Symbol] ruby_name
@return [String] The command-line version of RUBY_NAME, replacing any ‘_’
with ‘-’
# File lib/ame-1.0/method.rb, line 16 def name(ruby_name) ruby_name.to_s.gsub('_', '-') end
# File lib/ame-1.0/method.rb, line 21 def initialize(ruby_name, klass, description, options, arguments) @ruby_name, @class, @description, @options, @arguments = ruby_name, klass, description, options, arguments end
@param [String] name @return [Symbol] The Ruby version of NAME, possibly the name of the
method given on the command-line, replacing any ‘-’ with ‘_’.
# File lib/ame-1.0/method.rb, line 9 def ruby_name(name) name.gsub('-', '_').to_sym end
Public Instance Methods
Call the receiver’s method on INSTANCE with ARGUMENTS and OPTIONS, retrieving any default values for them if they’re nil. @api internal @param [Class] instance @param [Array<Object>, nil] arguments @param [Hash<String, Object>] options @raise (see Options#process) @raise (see Arguments#process) @return [self]
# File lib/ame-1.0/method.rb, line 48 def call(instance, arguments = nil, options = nil) options, _ = @options.process([]) unless options arguments ||= @arguments.process(options, []) instance.send @ruby_name, *(arguments + (options.empty? ? [] : [options])) self end
@return [String] The command-line name of the receiver
# File lib/ame-1.0/method.rb, line 65 def name @name ||= self.class.name(@ruby_name) end
Process ARGUMENTS as a set of {Options} and {Arguments}, then {#call} the receiver’s method on INSTANCE with them. @api internal @param [Class] instance @param [Array<String>] arguments @raise (see Options#process) @raise (see Arguments#process) @return [self]
# File lib/ame-1.0/method.rb, line 34 def process(instance, arguments) options, remainder = @options.process(arguments) call(instance, @arguments.process(options, remainder), options) end
@return [String] The full command-line name of the receiver, including the
class that this method belongs to’s {Class.fullname}
# File lib/ame-1.0/method.rb, line 71 def qualified_name [@class.fullname, name].reject(&:empty?).join(' ') end