Class: RBS::Types::Proc

Inherits:
Object
  • Object
show all
Includes:
_TypeBase
Defined in:
lib/rbs/types.rb,
sig/types.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location:, type:, block:, self_type: nil) ⇒ Proc

Returns a new instance of Proc.

Parameters:

  • location: (loc, nil)
  • type: (function)
  • self_type: (t, nil) (defaults to: nil)
  • block: (Block, nil)


1455
1456
1457
1458
1459
1460
# File 'lib/rbs/types.rb', line 1455

def initialize(location:, type:, block:, self_type: nil)
  @type = type
  @block = block
  @location = location
  @self_type = self_type
end

Instance Attribute Details

#blockBlock? (readonly)

Returns the value of attribute block.

Returns:



1451
1452
1453
# File 'lib/rbs/types.rb', line 1451

def block
  @block
end

#locationloc? (readonly)

Returns the value of attribute location.

Returns:

  • (loc, nil)


1453
1454
1455
# File 'lib/rbs/types.rb', line 1453

def location
  @location
end

#self_typet? (readonly)

Returns the value of attribute self_type.

Returns:

  • (t, nil)


1452
1453
1454
# File 'lib/rbs/types.rb', line 1452

def self_type
  @self_type
end

#typefunction (readonly)

Returns the value of attribute type.

Returns:

  • (function)


1450
1451
1452
# File 'lib/rbs/types.rb', line 1450

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



1462
1463
1464
# File 'lib/rbs/types.rb', line 1462

def ==(other)
  other.is_a?(Proc) && other.type == type && other.block == block && other.self_type == self_type
end

#each_type(&block) ⇒ Object



1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
# File 'lib/rbs/types.rb', line 1516

def each_type(&block)
  if block
    type.each_type(&block)
    yield self_type if self_type
    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



1472
1473
1474
1475
1476
1477
# File 'lib/rbs/types.rb', line 1472

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

Returns:

  • (Boolean)


1555
1556
1557
# File 'lib/rbs/types.rb', line 1555

def has_classish_type?
  each_type.any? {|type| type.has_classish_type? }
end

#has_self_type?Boolean

Returns:

  • (Boolean)


1551
1552
1553
# File 'lib/rbs/types.rb', line 1551

def has_self_type?
  each_type.any? {|type| type.has_self_type? }
end

#hashObject



1468
1469
1470
# File 'lib/rbs/types.rb', line 1468

def hash
  self.class.hash ^ type.hash ^ block.hash ^ self_type.hash
end

#map_typeProc #map_typeEnumerator[t, Proc]

Overloads:

  • #map_typeProc

    Returns:

  • #map_typeEnumerator[t, Proc]

    Returns:

    • (Enumerator[t, Proc])

Yields:

Yield Parameters:

  • arg0 (t)

Yield Returns:

  • (t)


1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
# File 'lib/rbs/types.rb', line 1538

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



1529
1530
1531
1532
1533
1534
1535
1536
# File 'lib/rbs/types.rb', line 1529

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



1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
# File 'lib/rbs/types.rb', line 1489

def sub(s)
  return self if s.empty?

  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



1479
1480
1481
1482
1483
1484
1485
1486
1487
# File 'lib/rbs/types.rb', line 1479

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



1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
# File 'lib/rbs/types.rb', line 1500

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

Returns:

  • (Boolean)


1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
# File 'lib/rbs/types.rb', line 1559

def with_nonreturn_void?
  if type.with_nonreturn_void? || self_type&.with_nonreturn_void? # steep:ignore DeprecatedReference
    true
  else
    if block = block()
      block.type.with_nonreturn_void? || block.self_type&.with_nonreturn_void? || false # steep:ignore DeprecatedReference
    else
      false
    end
  end
end