Class: Steep::Subtyping::Relation
- Defined in:
- lib/steep/subtyping/relation.rb
Instance Attribute Summary collapse
-
#sub_type ⇒ Object
readonly
Returns the value of attribute sub_type.
-
#super_type ⇒ Object
readonly
Returns the value of attribute super_type.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #assert_type(type) ⇒ Object
- #block! ⇒ Object
- #block? ⇒ Boolean
- #flip ⇒ Object
- #function! ⇒ Object
- #function? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(sub_type:, super_type:) ⇒ Relation
constructor
A new instance of Relation.
- #interface! ⇒ Object
- #interface? ⇒ Boolean
- #map ⇒ Object
- #method! ⇒ Object
- #method? ⇒ Boolean
- #params! ⇒ Object
- #params? ⇒ Boolean
- #to_ary ⇒ Object
- #to_s ⇒ Object
- #type! ⇒ Object
- #type? ⇒ Boolean
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_type ⇒ Object (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_type ⇒ Object (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 |
#assert_type(type) ⇒ Object
56 57 58 59 60 |
# File 'lib/steep/subtyping/relation.rb', line 56 def assert_type(type) unless __send__(:"#{type}?") raise "#{type}? is expected but: sub_type=#{sub_type.class}, super_type=#{super_type.class}" end end |
#block! ⇒ Object
82 83 84 |
# File 'lib/steep/subtyping/relation.rb', line 82 def block! assert_type(:block) end |
#block? ⇒ Boolean
51 52 53 54 |
# File 'lib/steep/subtyping/relation.rb', line 51 def block? (sub_type.is_a?(Interface::Block) || !sub_type) && (!super_type || super_type.is_a?(Interface::Block)) end |
#flip ⇒ Object
93 94 95 96 97 98 |
# File 'lib/steep/subtyping/relation.rb', line 93 def flip self.class.new( sub_type: super_type, super_type: sub_type ) end |
#function! ⇒ Object
74 75 76 |
# File 'lib/steep/subtyping/relation.rb', line 74 def function! assert_type(:function) end |
#function? ⇒ Boolean
43 44 45 |
# File 'lib/steep/subtyping/relation.rb', line 43 def function? sub_type.is_a?(Interface::Function) && super_type.is_a?(Interface::Function) end |
#hash ⇒ Object
12 13 14 |
# File 'lib/steep/subtyping/relation.rb', line 12 def hash self.class.hash ^ sub_type.hash ^ super_type.hash end |
#interface! ⇒ Object
66 67 68 |
# File 'lib/steep/subtyping/relation.rb', line 66 def interface! assert_type(:interface) end |
#interface? ⇒ Boolean
34 35 36 |
# File 'lib/steep/subtyping/relation.rb', line 34 def interface? sub_type.is_a?(Interface::Shape) && super_type.is_a?(Interface::Shape) end |
#map ⇒ Object
86 87 88 89 90 91 |
# File 'lib/steep/subtyping/relation.rb', line 86 def map self.class.new( sub_type: yield(sub_type), super_type: yield(super_type) ) end |
#method! ⇒ Object
70 71 72 |
# File 'lib/steep/subtyping/relation.rb', line 70 def method! assert_type(:method) end |
#method? ⇒ Boolean
38 39 40 41 |
# File 'lib/steep/subtyping/relation.rb', line 38 def method? (sub_type.is_a?(Interface::Shape::Entry) || sub_type.is_a?(Interface::MethodType)) && (super_type.is_a?(Interface::Shape::Entry) || super_type.is_a?(Interface::MethodType)) end |
#params! ⇒ Object
78 79 80 |
# File 'lib/steep/subtyping/relation.rb', line 78 def params! assert_type(:params) end |
#params? ⇒ Boolean
47 48 49 |
# File 'lib/steep/subtyping/relation.rb', line 47 def params? sub_type.is_a?(Interface::Function::Params) && super_type.is_a?(Interface::Function::Params) end |
#to_ary ⇒ Object
26 27 28 |
# File 'lib/steep/subtyping/relation.rb', line 26 def to_ary [sub_type, super_type] end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/steep/subtyping/relation.rb', line 22 def to_s "#{sub_type} <: #{super_type}" end |
#type! ⇒ Object
62 63 64 |
# File 'lib/steep/subtyping/relation.rb', line 62 def type! assert_type(:type) end |
#type? ⇒ Boolean
30 31 32 |
# File 'lib/steep/subtyping/relation.rb', line 30 def type? !interface? && !method? && !function? && !params? && !block? end |