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
- #has_classish_type? ⇒ Boolean
- #has_self_type? ⇒ Boolean
- #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
- #with_nonreturn_void? ⇒ Boolean
Constructor Details
#initialize(location:, type:, block:, self_type: nil) ⇒ Proc
Returns a new instance of Proc.
1344 1345 1346 1347 1348 1349 |
# File 'lib/rbs/types.rb', line 1344 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.
1340 1341 1342 |
# File 'lib/rbs/types.rb', line 1340 def block @block end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
1342 1343 1344 |
# File 'lib/rbs/types.rb', line 1342 def location @location end |
#self_type ⇒ Object (readonly)
Returns the value of attribute self_type.
1341 1342 1343 |
# File 'lib/rbs/types.rb', line 1341 def self_type @self_type end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
1339 1340 1341 |
# File 'lib/rbs/types.rb', line 1339 def type @type end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
1351 1352 1353 |
# File 'lib/rbs/types.rb', line 1351 def ==(other) other.is_a?(Proc) && other.type == type && other.block == block && other.self_type == self_type end |
#each_type(&block) ⇒ Object
1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 |
# File 'lib/rbs/types.rb', line 1403 def each_type(&block) if block type.each_type(&block) self.block&.type&.each_type(&block) if self_type = self.block&.self_type yield self_type end else enum_for :each_type end end |
#free_variables(set = ) ⇒ Object
1361 1362 1363 1364 1365 1366 |
# File 'lib/rbs/types.rb', line 1361 def free_variables(set = Set[]) type.free_variables(set) block&.type&.free_variables(set) self_type&.free_variables(set) set end |
#has_classish_type? ⇒ Boolean
1441 1442 1443 |
# File 'lib/rbs/types.rb', line 1441 def has_classish_type? each_type.any? {|type| type.has_classish_type? } end |
#has_self_type? ⇒ Boolean
1437 1438 1439 |
# File 'lib/rbs/types.rb', line 1437 def has_self_type? each_type.any? {|type| type.has_self_type? } end |
#hash ⇒ Object
1357 1358 1359 |
# File 'lib/rbs/types.rb', line 1357 def hash self.class.hash ^ type.hash ^ block.hash ^ self_type.hash end |
#map_type(&block) ⇒ Object
1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 |
# File 'lib/rbs/types.rb', line 1424 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
1415 1416 1417 1418 1419 1420 1421 1422 |
# File 'lib/rbs/types.rb', line 1415 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
1378 1379 1380 1381 1382 1383 1384 1385 |
# File 'lib/rbs/types.rb', line 1378 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
1368 1369 1370 1371 1372 1373 1374 1375 1376 |
# File 'lib/rbs/types.rb', line 1368 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
1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 |
# File 'lib/rbs/types.rb', line 1387 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 |
#with_nonreturn_void? ⇒ Boolean
1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 |
# File 'lib/rbs/types.rb', line 1445 def with_nonreturn_void? if type.with_nonreturn_void? true else if block = block() block.type.with_nonreturn_void? || block.self_type&.with_nonreturn_void? || false else false end end end |