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.



651
652
653
654
655
# File 'lib/rbs/types.rb', line 651

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

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



649
650
651
# File 'lib/rbs/types.rb', line 649

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



648
649
650
# File 'lib/rbs/types.rb', line 648

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



647
648
649
# File 'lib/rbs/types.rb', line 647

def type
  @type
end

Instance Method Details

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



657
658
659
# File 'lib/rbs/types.rb', line 657

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

#hashObject



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

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

#map_type(&block) ⇒ Object



667
668
669
670
671
672
673
# File 'lib/rbs/types.rb', line 667

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



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

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

#to_sObject



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

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