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.



730
731
732
733
734
# File 'lib/rbs/types.rb', line 730

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

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



728
729
730
# File 'lib/rbs/types.rb', line 728

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



727
728
729
# File 'lib/rbs/types.rb', line 727

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



726
727
728
# File 'lib/rbs/types.rb', line 726

def type
  @type
end

Instance Method Details

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



736
737
738
# File 'lib/rbs/types.rb', line 736

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

#hashObject



742
743
744
# File 'lib/rbs/types.rb', line 742

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

#map_type(&block) ⇒ Object



746
747
748
749
750
751
752
# File 'lib/rbs/types.rb', line 746

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



754
755
756
# File 'lib/rbs/types.rb', line 754

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

#to_sObject



758
759
760
761
762
763
764
765
766
767
768
# File 'lib/rbs/types.rb', line 758

def to_s
  if name
    if Parser::KEYWORDS.include?(name.to_s)
      "#{type} `#{name}`"
    else
      "#{type} #{name}"
    end
  else
    "#{type}"
  end
end