class Loom::MethodSignature

Used to analyze the arguments of a method.

Attributes

block_args[R]
key_args[R]
keyreq_args[R]
keyrest_args[R]
opt_args[R]
req_args[R]
rest_args[R]

Public Class Methods

new(proc_or_method) click to toggle source

@param proc_or_method [#parameters] A {Proc} or {Method}

# File lib/loom/method_signature.rb, line 17
def initialize(proc_or_method)
  @parameter_list = proc_or_method.parameters
  @req_args = find_by_type ParamType::REQ
  @opt_args = find_by_type ParamType::OPT
  @rest_args = find_by_type ParamType::REST
  @keyreq_args = find_by_type ParamType::KEYREQ
  @key_args = find_by_type ParamType::KEY
  @keyrest_args = find_by_type ParamType::KEYREST
  @block_args = find_by_type ParamType::BLOCK
end

Public Instance Methods

find_by_type(type) click to toggle source
# File lib/loom/method_signature.rb, line 31
def find_by_type(type)
  @parameter_list.find_all { |tuple| tuple.first == type }
end
method_missing(name, *args) click to toggle source

Defines has_xyz_args? methods for each {ParamType}.

Calls superclass method
# File lib/loom/method_signature.rb, line 36
def method_missing(name, *args)
  match_data = name.to_s.match /^has_([^?]+)_args\?$/
  if match_data
    method = "%s_args" % [match_data[1]]
    !self.send(method.to_sym).empty?
  else
    super name, *args
  end
end