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.
1368 1369 1370 1371 1372 1373 |
# File 'lib/rbs/types.rb', line 1368 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.
1364 1365 1366 |
# File 'lib/rbs/types.rb', line 1364 def block @block end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
1366 1367 1368 |
# File 'lib/rbs/types.rb', line 1366 def location @location end |
#self_type ⇒ Object (readonly)
Returns the value of attribute self_type.
1365 1366 1367 |
# File 'lib/rbs/types.rb', line 1365 def self_type @self_type end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
1363 1364 1365 |
# File 'lib/rbs/types.rb', line 1363 def type @type end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
1375 1376 1377 |
# File 'lib/rbs/types.rb', line 1375 def ==(other) other.is_a?(Proc) && other.type == type && other.block == block && other.self_type == self_type end |
#each_type(&block) ⇒ Object
1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 |
# File 'lib/rbs/types.rb', line 1427 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
1385 1386 1387 1388 1389 1390 |
# File 'lib/rbs/types.rb', line 1385 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
1465 1466 1467 |
# File 'lib/rbs/types.rb', line 1465 def has_classish_type? each_type.any? {|type| type.has_classish_type? } end |
#has_self_type? ⇒ Boolean
1461 1462 1463 |
# File 'lib/rbs/types.rb', line 1461 def has_self_type? each_type.any? {|type| type.has_self_type? } end |
#hash ⇒ Object
1381 1382 1383 |
# File 'lib/rbs/types.rb', line 1381 def hash self.class.hash ^ type.hash ^ block.hash ^ self_type.hash end |
#map_type(&block) ⇒ Object
1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 |
# File 'lib/rbs/types.rb', line 1448 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
1439 1440 1441 1442 1443 1444 1445 1446 |
# File 'lib/rbs/types.rb', line 1439 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
1402 1403 1404 1405 1406 1407 1408 1409 |
# File 'lib/rbs/types.rb', line 1402 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
1392 1393 1394 1395 1396 1397 1398 1399 1400 |
# File 'lib/rbs/types.rb', line 1392 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
1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 |
# File 'lib/rbs/types.rb', line 1411 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
1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 |
# File 'lib/rbs/types.rb', line 1469 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 |