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:) ⇒ Proc

[ GitHub ]

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

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

Instance Attribute Details

#block (readonly)

[ GitHub ]

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

attr_reader :block

#location (readonly)

[ GitHub ]

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

attr_reader :location

#type (readonly)

[ GitHub ]

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

attr_reader :type

Instance Method Details

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

[ GitHub ]

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

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

#each_type(&block)

[ GitHub ]

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

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

[ GitHub ]

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

alias eql? ==

#free_variables(set = )

[ GitHub ]

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

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

#hash

[ GitHub ]

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

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

#map_type_name(&block)

[ GitHub ]

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

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)

[ GitHub ]

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

def sub(s)
  self.class.new(type: type.sub(s), block: block&.sub(s), location: location)
end

#to_json(state = _ = nil)

[ GitHub ]

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

def to_json(state = _ = nil)
  {
    class: :proc,
    type: type,
    block: block,
    location: location
  }.to_json(state)
end

#to_s(level = 0)

[ GitHub ]

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

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