class Ame::Method

A method in its defined state. @api developer

Attributes

arguments[R]

@return [Arguments] The arguments of the receiver

description[R]

@return [String] The description of the receiver

options[R]

@return [Options] The options of the receiver

Public Class Methods

name(ruby_name) click to toggle source

@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
new(ruby_name, klass, description, options, arguments) click to toggle source
# 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
ruby_name(name) click to toggle source

@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(instance, arguments = nil, options = nil) click to toggle source

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
name() click to toggle source

@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(instance, arguments) click to toggle source

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
qualified_name() click to toggle source

@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