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.



884
885
886
887
888
# File 'lib/rbs/types.rb', line 884

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

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



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

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



881
882
883
# File 'lib/rbs/types.rb', line 881

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

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



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

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

#hashObject



896
897
898
# File 'lib/rbs/types.rb', line 896

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

#map_type(&block) ⇒ Object



900
901
902
903
904
905
906
# File 'lib/rbs/types.rb', line 900

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



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

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

#to_sObject



912
913
914
915
916
917
918
919
920
921
922
# File 'lib/rbs/types.rb', line 912

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