Class: RBS::Types::Proc

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/types.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location:, type:) ⇒ Proc

Returns a new instance of Proc.



948
949
950
951
# File 'lib/rbs/types.rb', line 948

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

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



946
947
948
# File 'lib/rbs/types.rb', line 946

def location
  @location
end

#typeObject (readonly)

Returns the value of attribute type.



945
946
947
# File 'lib/rbs/types.rb', line 945

def type
  @type
end

Instance Method Details

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



953
954
955
# File 'lib/rbs/types.rb', line 953

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

#each_type(&block) ⇒ Object



979
980
981
982
983
984
985
# File 'lib/rbs/types.rb', line 979

def each_type(&block)
  if block_given?
    type.each_type(&block)
  else
    enum_for :each_type
  end
end

#free_variables(set) ⇒ Object



963
964
965
# File 'lib/rbs/types.rb', line 963

def free_variables(set)
  type.free_variables(set)
end

#hashObject



959
960
961
# File 'lib/rbs/types.rb', line 959

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

#map_type_name(&block) ⇒ Object



987
988
989
990
991
992
# File 'lib/rbs/types.rb', line 987

def map_type_name(&block)
  Proc.new(
    type: type.map_type_name(&block),
    location: location
  )
end

#sub(s) ⇒ Object



971
972
973
# File 'lib/rbs/types.rb', line 971

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

#to_json(*a) ⇒ Object



967
968
969
# File 'lib/rbs/types.rb', line 967

def to_json(*a)
  { class: :proc, type: type, location: location }.to_json(*a)
end

#to_s(level = 0) ⇒ Object



975
976
977
# File 'lib/rbs/types.rb', line 975

def to_s(level = 0)
  "^(#{type.param_to_s}) -> #{type.return_to_s}".lstrip
end