Class: Quacks::Signature

Inherits:
Object show all
Defined in:
lib/quacks/signature.rb

Overview

Internal: The class responsible for massaging parameters before passing them to the signatured method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*signature) ⇒ Signature

Internal: Initialize a signature object.

signature - The Symbol or Hash conversion method(s) that depicts this

signature.


10
11
12
# File 'lib/quacks/signature.rb', line 10

def initialize(*signature)
  @signature = signature
end

Instance Attribute Details

#signatureObject (readonly)

Returns the value of attribute signature.



4
5
6
# File 'lib/quacks/signature.rb', line 4

def signature
  @signature
end

Instance Method Details

#apply!(*args) ⇒ Object

Internal: Convert the given arguments, with the given conversion methods.

Examples:

Quacks::Signature.new(:to_i, bignum: :to_s).apply!('1', 100)
#=> [1, { bignum: '100' }]

Returns an Array of arguments. Raises Quacks::SignatureError if the arguments could not be converted. Raises Quacks::WrongNumberOfArgumentsError if wrong number of arguments.



24
25
26
27
28
29
# File 'lib/quacks/signature.rb', line 24

def apply!(*args)
  validate args, signature
  signature.each_with_index.map do |arg_signature, i|
    convert! args[i], arg_signature
  end
end