123456789_123456789_123456789_123456789_123456789_

Class: RBS::Types::Function::Param

Relationships & Source Files
Inherits: Object
Defined in: lib/rbs/types.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(type:, name:, location: nil) ⇒ Param

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 877

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

Instance Attribute Details

#location (readonly)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 875

attr_reader :location

#name (readonly)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 874

attr_reader :name

#type (readonly)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 873

attr_reader :type

Instance Method Details

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

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 883

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

#eql?(other)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 887

alias eql? ==

#hash

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 889

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

#map_type(&block)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 893

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)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 901

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

#to_s

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 905

def to_s
  if name
    if name.match?(/\A[a-zA-Z0-9_]+\z/)
      "#{type} #{name}"
    else
      "#{type} `#{name}`"
    end
  else
    "#{type}"
  end
end