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.



864
865
866
867
# File 'lib/rbs/types.rb', line 864

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

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



862
863
864
# File 'lib/rbs/types.rb', line 862

def location
  @location
end

#typeObject (readonly)

Returns the value of attribute type.



861
862
863
# File 'lib/rbs/types.rb', line 861

def type
  @type
end

Instance Method Details

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



869
870
871
# File 'lib/rbs/types.rb', line 869

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

#each_type(&block) ⇒ Object



895
896
897
898
899
900
901
# File 'lib/rbs/types.rb', line 895

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

#free_variables(set) ⇒ Object



879
880
881
# File 'lib/rbs/types.rb', line 879

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

#hashObject



875
876
877
# File 'lib/rbs/types.rb', line 875

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

#sub(s) ⇒ Object



887
888
889
# File 'lib/rbs/types.rb', line 887

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

#to_json(*a) ⇒ Object



883
884
885
# File 'lib/rbs/types.rb', line 883

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

#to_s(level = 0) ⇒ Object



891
892
893
# File 'lib/rbs/types.rb', line 891

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