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.



856
857
858
859
860
# File 'lib/rbs/types.rb', line 856

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

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



854
855
856
# File 'lib/rbs/types.rb', line 854

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



853
854
855
# File 'lib/rbs/types.rb', line 853

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



852
853
854
# File 'lib/rbs/types.rb', line 852

def type
  @type
end

Instance Method Details

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



862
863
864
# File 'lib/rbs/types.rb', line 862

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

#hashObject



868
869
870
# File 'lib/rbs/types.rb', line 868

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

#map_type(&block) ⇒ Object



872
873
874
875
876
877
878
# File 'lib/rbs/types.rb', line 872

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



880
881
882
# File 'lib/rbs/types.rb', line 880

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

#to_sObject



884
885
886
887
888
889
890
# File 'lib/rbs/types.rb', line 884

def to_s
  if name
    "#{type} #{name}"
  else
    "#{type}"
  end
end