Class: Wool::SexpAnalysis::Protocols::ClassProtocol

Inherits:
Base
  • Object
show all
Defined in:
lib/wool/analysis/protocols.rb

Overview

A protocol that has the same signatures as a given class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ ClassProtocol

Initializes the class protocol with the given class.

Parameters:

  • klass (WoolClass)

    the wool class whose protocol we are representing



56
57
58
# File 'lib/wool/analysis/protocols.rb', line 56

def initialize(klass)
  @class_used = klass
end

Instance Attribute Details

#class_usedObject (readonly)

Returns the value of attribute class_used.



51
52
53
# File 'lib/wool/analysis/protocols.rb', line 51

def class_used
  @class_used
end

Instance Method Details

#<=>(other) ⇒ -1, ...

Compares two ClassProtocols. Has a short-circuit check if two protocols refer to the same class or not. Otherwise, it has to check the signatures.

Parameters:

Returns:

  • (-1, 0, 1)

    a standard comparison result.



65
66
67
68
69
70
# File 'lib/wool/analysis/protocols.rb', line 65

def <=>(other)
  if ClassProtocol === other && self.class_used == other.class_used
  then return 0
  else self.signatures <=> other.signatures
  end
end

#signaturesArray<Signature>

Returns all the signatures that the class responds to, since this protocol has the same signatures.

Returns:

  • (Array<Signature>)

    the supported signatures for this protocol.



76
77
78
# File 'lib/wool/analysis/protocols.rb', line 76

def signatures
  @class_used.signatures
end