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.



664
665
666
667
668
# File 'lib/rbs/types.rb', line 664

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

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



662
663
664
# File 'lib/rbs/types.rb', line 662

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



661
662
663
# File 'lib/rbs/types.rb', line 661

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



660
661
662
# File 'lib/rbs/types.rb', line 660

def type
  @type
end

Instance Method Details

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



670
671
672
# File 'lib/rbs/types.rb', line 670

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

#hashObject



676
677
678
# File 'lib/rbs/types.rb', line 676

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

#map_type(&block) ⇒ Object



680
681
682
683
684
685
686
# File 'lib/rbs/types.rb', line 680

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



688
689
690
# File 'lib/rbs/types.rb', line 688

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

#to_sObject



692
693
694
695
696
697
698
699
700
701
702
# File 'lib/rbs/types.rb', line 692

def to_s
  if name
    if /\A#{Parser::KEYWORDS_RE}\z/.match?(name)
      "#{type} `#{name}`"
    else
      "#{type} #{name}"
    end
  else
    "#{type}"
  end
end