Class: RBS::Types::Function::Param

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, name:, location: nil) ⇒ Param

Returns a new instance of Param.



921
922
923
924
925
# File 'lib/rbs/types.rb', line 921

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

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



919
920
921
# File 'lib/rbs/types.rb', line 919

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



918
919
920
# File 'lib/rbs/types.rb', line 918

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



917
918
919
# File 'lib/rbs/types.rb', line 917

def type
  @type
end

Instance Method Details

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



927
928
929
# File 'lib/rbs/types.rb', line 927

def ==(other)
  other.is_a?(Param) && other.type == type && other.name == name
end

#hashObject



933
934
935
# File 'lib/rbs/types.rb', line 933

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

#map_type(&block) ⇒ Object



937
938
939
940
941
942
943
# File 'lib/rbs/types.rb', line 937

def map_type(&block)
  if block
    Param.new(name: name, type: yield(type), location: location)
  else
    enum_for :map_type
  end
end

#to_json(state = nil) ⇒ Object



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

def to_json(state = nil)
  { type: type, name: name }.to_json(state)
end

#to_sObject



949
950
951
952
953
954
955
956
957
958
959
# File 'lib/rbs/types.rb', line 949

def to_s
  if name
    if name.match?(/\A[a-zA-Z0-9_]+\z/)
      "#{type} #{name}"
    else
      "#{type} `#{name}`"
    end
  else
    "#{type}"
  end
end