class RBS::Types::Proc

Attributes

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

Public Class Methods

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

Public Instance Methods

==(other) click to toggle source
# File rbs-2.1.0/lib/rbs/types.rb, line 1068
def ==(other)
  other.is_a?(Proc) && other.type == type && other.block == block
end
Also aliased as: eql?
each_type(&block) click to toggle source
# File rbs-2.1.0/lib/rbs/types.rb, line 1110
def each_type(&block)
  if block
    type.each_type(&block)
    self.block&.type&.each_type(&block)
  else
    enum_for :each_type
  end
end
eql?(other)
Alias for: ==
free_variables(set = Set[]) click to toggle source
# File rbs-2.1.0/lib/rbs/types.rb, line 1078
def free_variables(set = Set[])
  type.free_variables(set)
  block&.type&.free_variables(set)
  set
end
hash() click to toggle source
# File rbs-2.1.0/lib/rbs/types.rb, line 1074
def hash
  self.class.hash ^ type.hash ^ block.hash
end
map_type(&block) click to toggle source
# File rbs-2.1.0/lib/rbs/types.rb, line 1127
def map_type(&block)
  if block
    Proc.new(
      type: type.map_type(&block),
      block: self.block&.map_type(&block),
      location: location
    )
  else
    enum_for :map_type
  end
end
map_type_name(&block) click to toggle source
# File rbs-2.1.0/lib/rbs/types.rb, line 1119
def map_type_name(&block)
  Proc.new(
    type: type.map_type_name(&block),
    block: self.block&.map_type {|type| type.map_type_name(&block) },
    location: location
  )
end
sub(s) click to toggle source
# File rbs-2.1.0/lib/rbs/types.rb, line 1093
def sub(s)
  self.class.new(type: type.sub(s), block: block&.sub(s), location: location)
end
to_json(state = _ = nil) click to toggle source
# File rbs-2.1.0/lib/rbs/types.rb, line 1084
def to_json(state = _ = nil)
  {
    class: :proc,
    type: type,
    block: block,
    location: location
  }.to_json(state)
end
to_s(level = 0) click to toggle source
# File rbs-2.1.0/lib/rbs/types.rb, line 1097
def to_s(level = 0)
  case
  when b = block
    if b.required
      "^(#{type.param_to_s}) { (#{b.type.param_to_s}) -> #{b.type.return_to_s} } -> #{type.return_to_s}"
    else
      "^(#{type.param_to_s}) ?{ (#{b.type.param_to_s}) -> #{b.type.return_to_s} } -> #{type.return_to_s}"
    end
  else
    "^(#{type.param_to_s}) -> #{type.return_to_s}"
  end
end