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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Param.

Parameters:

  • type: (t)
  • name: (Symbol, nil)
  • location: (loc, nil) (defaults to: nil)


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

#locationloc? (readonly)

Returns the value of attribute location.

Returns:

  • (loc, nil)


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

def location
  @location
end

#nameSymbol? (readonly)

Returns the value of attribute name.

Returns:

  • (Symbol, nil)


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

def name
  @name
end

#typet (readonly)

Returns the value of attribute type.

Returns:

  • (t)


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_typeParam #map_typeEnumerator[t, Param]

Overloads:

  • #map_typeParam

    Returns:

  • #map_typeEnumerator[t, Param]

    Returns:

Yields:

Yield Parameters:

  • arg0 (t)

Yield Returns:

  • (t)


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