Module: MethodSignatureMixin

Included in:
Method, UnboundMethod
Defined in:
lib/contract/integration.rb

Overview

Modifies Method and UnboundMethod so that signatures set by Module.signatures can be retrieved.

Note that this can only work when the method origin and definition name are known which is the reason for ruby-contract currently overloading all methods that return a method.

This could be greatly simplified it www.rcrchive.net/rcr/show/292 were to be accepted. You can help the development of ruby-contract by voting for that RCR.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject (readonly)

:nodoc:



582
583
584
# File 'lib/contract/integration.rb', line 582

def name
  @name
end

#originObject (readonly)

:nodoc:



581
582
583
# File 'lib/contract/integration.rb', line 581

def origin
  @origin
end

Instance Method Details

#has_signature?Boolean

Returns whether a signatue for this method was defined via Module#signature.

Returns:

  • (Boolean)


608
# File 'lib/contract/integration.rb', line 608

def has_signature?() @has_signature end

#initialize(origin = nil, name = nil) ⇒ Object

:nodoc:



584
585
586
587
588
589
590
591
592
593
594
595
596
597
# File 'lib/contract/integration.rb', line 584

def initialize(origin = nil, name = nil) # :nodoc:
  @origin, @name = origin, name
  @signature = nil
  @has_signature = false
  signatures = origin.instance_variable_get(:@signatures)
  @signature = if signatures and signatures.include?(name) then
    @has_signature = true
    signatures[name].last[0, 2]
  elsif self.arity >= 0 then
    [[:any] * self.arity, {}]
  else
    [[:any] * ~self.arity, { :allow_trailing => true }]
  end
end

#signatureObject

Returns the signature of this method in the form of [fixed types, options]. If no signature was specified via Module#signature it will still return something useful.

This information can be useful in meta programming.



604
# File 'lib/contract/integration.rb', line 604

def signature() @signature end