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.



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

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

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



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

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

#hashObject



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

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

#map_typeObject



675
676
677
678
679
680
681
# File 'lib/rbs/types.rb', line 675

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

#to_json(*a) ⇒ Object



683
684
685
# File 'lib/rbs/types.rb', line 683

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

#to_sObject



687
688
689
690
691
692
693
694
695
696
697
# File 'lib/rbs/types.rb', line 687

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