Class: RBS::MethodType
- Inherits:
-
Object
- Object
- RBS::MethodType
- Defined in:
- lib/rbs/method_type.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#type_params ⇒ Object
readonly
Returns the value of attribute type_params.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #each_type(&block) ⇒ Object
- #free_variables(set = Set.new) ⇒ Object
-
#initialize(type_params:, type:, block:, location:) ⇒ MethodType
constructor
A new instance of MethodType.
- #map_type(&block) ⇒ Object
- #sub(s) ⇒ Object
- #to_json(state = _ = nil) ⇒ Object
- #to_s ⇒ Object
- #update(type_params: self.type_params, type: self.type, block: self.block, location: self.location) ⇒ Object
Constructor Details
#initialize(type_params:, type:, block:, location:) ⇒ MethodType
Returns a new instance of MethodType.
8 9 10 11 12 13 |
# File 'lib/rbs/method_type.rb', line 8 def initialize(type_params:, type:, block:, location:) @type_params = type_params @type = type @block = block @location = location end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
5 6 7 |
# File 'lib/rbs/method_type.rb', line 5 def block @block end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
6 7 8 |
# File 'lib/rbs/method_type.rb', line 6 def location @location end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/rbs/method_type.rb', line 4 def type @type end |
#type_params ⇒ Object (readonly)
Returns the value of attribute type_params.
3 4 5 |
# File 'lib/rbs/method_type.rb', line 3 def type_params @type_params end |
Instance Method Details
#==(other) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/rbs/method_type.rb', line 15 def ==(other) other.is_a?(MethodType) && other.type_params == type_params && other.type == type && other.block == block end |
#each_type(&block) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rbs/method_type.rb', line 65 def each_type(&block) if block type.each_type(&block) self.block&.yield_self do |b| b.type.each_type(&block) end else enum_for :each_type end end |
#free_variables(set = Set.new) ⇒ Object
48 49 50 51 52 |
# File 'lib/rbs/method_type.rb', line 48 def free_variables(set = Set.new) type.free_variables(set) block&.type&.free_variables(set) set.subtract(type_params) end |
#map_type(&block) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rbs/method_type.rb', line 54 def map_type(&block) self.class.new( type_params: type_params, type: type.map_type(&block), block: self.block&.yield_self do |b| Types::Block.new(type: b.type.map_type(&block), required: b.required) end, location: location ) end |
#sub(s) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/rbs/method_type.rb', line 31 def sub(s) s.without(*type_params).yield_self do |sub| map_type do |ty| ty.sub(sub) end end end |
#to_json(state = _ = nil) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/rbs/method_type.rb', line 22 def to_json(state = _ = nil) { type_params: type_params, type: type, block: block, location: location }.to_json(state) end |
#to_s ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/rbs/method_type.rb', line 76 def to_s s = case when (b = block) && b.required "(#{type.param_to_s}) { (#{b.type.param_to_s}) -> #{b.type.return_to_s} } -> #{type.return_to_s}" when b = block "(#{type.param_to_s}) ?{ (#{b.type.param_to_s}) -> #{b.type.return_to_s} } -> #{type.return_to_s}" else "(#{type.param_to_s}) -> #{type.return_to_s}" end if type_params.empty? s else "[#{type_params.join(", ")}] #{s}" end end |
#update(type_params: self.type_params, type: self.type, block: self.block, location: self.location) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/rbs/method_type.rb', line 39 def update(type_params: self.type_params, type: self.type, block: self.block, location: self.location) self.class.new( type_params: type_params, type: type, block: block, location: location ) end |