Class: Steep::Subtyping::Relation

Inherits:
Object
  • Object
show all
Defined in:
lib/steep/subtyping/relation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sub_type:, super_type:) ⇒ Relation

Returns a new instance of Relation.



7
8
9
10
# File 'lib/steep/subtyping/relation.rb', line 7

def initialize(sub_type:, super_type:)
  @sub_type = sub_type
  @super_type = super_type
end

Instance Attribute Details

#sub_typeObject (readonly)

Returns the value of attribute sub_type.



4
5
6
# File 'lib/steep/subtyping/relation.rb', line 4

def sub_type
  @sub_type
end

#super_typeObject (readonly)

Returns the value of attribute super_type.



5
6
7
# File 'lib/steep/subtyping/relation.rb', line 5

def super_type
  @super_type
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



16
17
18
# File 'lib/steep/subtyping/relation.rb', line 16

def ==(other)
  other.is_a?(self.class) && other.sub_type == sub_type && other.super_type == super_type
end

#flipObject



33
34
35
36
37
38
# File 'lib/steep/subtyping/relation.rb', line 33

def flip
  self.class.new(
    sub_type: super_type,
    super_type: sub_type
  )
end

#hashObject



12
13
14
# File 'lib/steep/subtyping/relation.rb', line 12

def hash
  self.class.hash ^ sub_type.hash ^ super_type.hash
end

#mapObject



26
27
28
29
30
31
# File 'lib/steep/subtyping/relation.rb', line 26

def map
  self.class.new(
    sub_type: yield(sub_type),
    super_type: yield(super_type)
  )
end

#to_sObject



22
23
24
# File 'lib/steep/subtyping/relation.rb', line 22

def to_s
  "#{sub_type} <: #{super_type}"
end