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



911
912
913
914
915
# File 'lib/rbs/types.rb', line 911

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

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



909
910
911
# File 'lib/rbs/types.rb', line 909

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



908
909
910
# File 'lib/rbs/types.rb', line 908

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



907
908
909
# File 'lib/rbs/types.rb', line 907

def type
  @type
end

Instance Method Details

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



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

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

#hashObject



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

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

#map_type(&block) ⇒ Object



927
928
929
930
931
932
933
# File 'lib/rbs/types.rb', line 927

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



935
936
937
# File 'lib/rbs/types.rb', line 935

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

#to_sObject



939
940
941
942
943
944
945
946
947
948
949
# File 'lib/rbs/types.rb', line 939

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