Class: RBS::Types::Proc
- Inherits:
-
Object
- Object
- RBS::Types::Proc
- Defined in:
- lib/rbs/types.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#self_type ⇒ Object
readonly
Returns the value of attribute self_type.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #each_type(&block) ⇒ Object
- #free_variables(set = ) ⇒ Object
- #hash ⇒ Object
-
#initialize(location:, type:, block:, self_type: nil) ⇒ Proc
constructor
A new instance of Proc.
- #map_type(&block) ⇒ Object
- #map_type_name(&block) ⇒ Object
- #sub(s) ⇒ Object
- #to_json(state = _ = nil) ⇒ Object
- #to_s(level = 0) ⇒ Object
Constructor Details
#initialize(location:, type:, block:, self_type: nil) ⇒ Proc
Returns a new instance of Proc.
1095 1096 1097 1098 1099 1100 |
# File 'lib/rbs/types.rb', line 1095 def initialize(location:, type:, block:, self_type: nil) @type = type @block = block @location = location @self_type = self_type end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
1091 1092 1093 |
# File 'lib/rbs/types.rb', line 1091 def block @block end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
1093 1094 1095 |
# File 'lib/rbs/types.rb', line 1093 def location @location end |
#self_type ⇒ Object (readonly)
Returns the value of attribute self_type.
1092 1093 1094 |
# File 'lib/rbs/types.rb', line 1092 def self_type @self_type end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
1090 1091 1092 |
# File 'lib/rbs/types.rb', line 1090 def type @type end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
1102 1103 1104 |
# File 'lib/rbs/types.rb', line 1102 def ==(other) other.is_a?(Proc) && other.type == type && other.block == block && other.self_type == self_type end |
#each_type(&block) ⇒ Object
1154 1155 1156 1157 1158 1159 1160 1161 |
# File 'lib/rbs/types.rb', line 1154 def each_type(&block) if block type.each_type(&block) self.block&.type&.each_type(&block) else enum_for :each_type end end |
#free_variables(set = ) ⇒ Object
1112 1113 1114 1115 1116 1117 |
# File 'lib/rbs/types.rb', line 1112 def free_variables(set = Set[]) type.free_variables(set) block&.type&.free_variables(set) self_type&.free_variables(set) set end |
#hash ⇒ Object
1108 1109 1110 |
# File 'lib/rbs/types.rb', line 1108 def hash self.class.hash ^ type.hash ^ block.hash ^ self_type.hash end |
#map_type(&block) ⇒ Object
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 |
# File 'lib/rbs/types.rb', line 1172 def map_type(&block) if block Proc.new( type: type.map_type(&block), block: self.block&.map_type(&block), self_type: self_type ? yield(self_type) : nil, location: location ) else enum_for :map_type end end |
#map_type_name(&block) ⇒ Object
1163 1164 1165 1166 1167 1168 1169 1170 |
# File 'lib/rbs/types.rb', line 1163 def map_type_name(&block) Proc.new( type: type.map_type_name(&block), block: self.block&.map_type {|type| type.map_type_name(&block) }, self_type: self_type&.map_type_name(&block), location: location ) end |
#sub(s) ⇒ Object
1129 1130 1131 1132 1133 1134 1135 1136 |
# File 'lib/rbs/types.rb', line 1129 def sub(s) self.class.new( type: type.sub(s), block: block&.sub(s), self_type: self_type&.sub(s), location: location ) end |
#to_json(state = _ = nil) ⇒ Object
1119 1120 1121 1122 1123 1124 1125 1126 1127 |
# File 'lib/rbs/types.rb', line 1119 def to_json(state = _ = nil) { class: :proc, type: type, block: block, location: location, self_type: self_type }.to_json(state) end |
#to_s(level = 0) ⇒ Object
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 |
# File 'lib/rbs/types.rb', line 1138 def to_s(level = 0) self_binding = SelfTypeBindingHelper.self_type_binding_to_s(self_type) block_self_binding = SelfTypeBindingHelper.self_type_binding_to_s(block&.self_type) case when b = block if b.required "^(#{type.param_to_s}) #{self_binding}{ (#{b.type.param_to_s}) #{block_self_binding}-> #{b.type.return_to_s} } -> #{type.return_to_s}" else "^(#{type.param_to_s}) #{self_binding}?{ (#{b.type.param_to_s}) #{block_self_binding}-> #{b.type.return_to_s} } -> #{type.return_to_s}" end else "^(#{type.param_to_s}) #{self_binding}-> #{type.return_to_s}" end end |