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:) ⇒ Param

Returns a new instance of Param.



582
583
584
585
# File 'lib/rbs/types.rb', line 582

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



580
581
582
# File 'lib/rbs/types.rb', line 580

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



579
580
581
# File 'lib/rbs/types.rb', line 579

def type
  @type
end

Instance Method Details

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



587
588
589
# File 'lib/rbs/types.rb', line 587

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

#hashObject



593
594
595
# File 'lib/rbs/types.rb', line 593

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

#map_typeObject



597
598
599
600
601
602
603
# File 'lib/rbs/types.rb', line 597

def map_type
  if block_given?
    Param.new(name: name, type: yield(type))
  else
    enum_for :map_type
  end
end

#to_json(*a) ⇒ Object



605
606
607
# File 'lib/rbs/types.rb', line 605

def to_json(*a)
  { type: type, name: name }.to_json(*a)
end

#to_sObject



609
610
611
612
613
614
615
616
617
618
619
# File 'lib/rbs/types.rb', line 609

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