123456789_123456789_123456789_123456789_123456789_

Class: RBS::Types::Proc

Relationships & Source Files
Inherits: Object
Defined in: lib/rbs/types.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(location:, type:, block:, self_type: nil) ⇒ Proc

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1355

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

Instance Attribute Details

#block (readonly)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1351

attr_reader :block

#has_classish_type?Boolean (readonly)

[ GitHub ]

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

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

#has_self_type?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1448

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

#location (readonly)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1353

attr_reader :location

#self_type (readonly)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1352

attr_reader :self_type

#type (readonly)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1350

attr_reader :type

#with_nonreturn_void?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1456

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

Instance Method Details

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

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1362

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

#each_type(&block)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1414

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 #==.

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1366

alias eql? ==

#free_variables(set = )

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1372

def free_variables(set = Set[])
  type.free_variables(set)
  block&.type&.free_variables(set)
  self_type&.free_variables(set)
  set
end

#hash

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1368

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

#map_type(&block)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1435

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)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1426

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)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1389

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)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1379

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)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1398

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