class RBS::Types::Proc

Attributes

block[R]
location[R]
self_type[R]
type[R]

Public Class Methods

new(location:, type:, block:, self_type: nil) click to toggle source
# File rbs-3.4.4/lib/rbs/types.rb, line 1245
def initialize(location:, type:, block:, self_type: nil)
  @type = type
  @block = block
  @location = location
  @self_type = self_type
end

Public Instance Methods

==(other) click to toggle source
# File rbs-3.4.4/lib/rbs/types.rb, line 1252
def ==(other)
  other.is_a?(Proc) && other.type == type && other.block == block && other.self_type == self_type
end
Also aliased as: eql?
each_type() { |self_type| ... } click to toggle source
# File rbs-3.4.4/lib/rbs/types.rb, line 1304
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
eql?(other)
Alias for: ==
free_variables(set = Set[]) click to toggle source
# File rbs-3.4.4/lib/rbs/types.rb, line 1262
def free_variables(set = Set[])
  type.free_variables(set)
  block&.type&.free_variables(set)
  self_type&.free_variables(set)
  set
end
has_classish_type?() click to toggle source
# File rbs-3.4.4/lib/rbs/types.rb, line 1342
def has_classish_type?
  each_type.any? {|type| type.has_classish_type? }
end
has_self_type?() click to toggle source
# File rbs-3.4.4/lib/rbs/types.rb, line 1338
def has_self_type?
  each_type.any? {|type| type.has_self_type? }
end
hash() click to toggle source
# File rbs-3.4.4/lib/rbs/types.rb, line 1258
def hash
  self.class.hash ^ type.hash ^ block.hash ^ self_type.hash
end
map_type() { |self_type| ... } click to toggle source
# File rbs-3.4.4/lib/rbs/types.rb, line 1325
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) click to toggle source
# File rbs-3.4.4/lib/rbs/types.rb, line 1316
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) click to toggle source
# File rbs-3.4.4/lib/rbs/types.rb, line 1279
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) click to toggle source
# File rbs-3.4.4/lib/rbs/types.rb, line 1269
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) click to toggle source
# File rbs-3.4.4/lib/rbs/types.rb, line 1288
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?() click to toggle source
# File rbs-3.4.4/lib/rbs/types.rb, line 1346
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