Class: RBS::Types::Tuple

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/types.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(types:, location:) ⇒ Tuple

Returns a new instance of Tuple.



342
343
344
345
# File 'lib/rbs/types.rb', line 342

def initialize(types:, location:)
  @types = types
  @location = location
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



340
341
342
# File 'lib/rbs/types.rb', line 340

def location
  @location
end

#typesObject (readonly)

Returns the value of attribute types.



339
340
341
# File 'lib/rbs/types.rb', line 339

def types
  @types
end

Instance Method Details

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



347
348
349
# File 'lib/rbs/types.rb', line 347

def ==(other)
  other.is_a?(Tuple) && other.types == types
end

#each_type(&block) ⇒ Object



382
383
384
385
386
387
388
# File 'lib/rbs/types.rb', line 382

def each_type(&block)
  if block_given?
    types.each(&block)
  else
    enum_for :each_type
  end
end

#free_variables(set = Set.new) ⇒ Object



357
358
359
360
361
362
363
# File 'lib/rbs/types.rb', line 357

def free_variables(set = Set.new)
  set.tap do
    types.each do |type|
      type.free_variables set
    end
  end
end

#hashObject



353
354
355
# File 'lib/rbs/types.rb', line 353

def hash
  self.class.hash ^ types.hash
end

#map_type_name(&block) ⇒ Object



390
391
392
393
394
395
# File 'lib/rbs/types.rb', line 390

def map_type_name(&block)
  Tuple.new(
    types: types.map {|type| type.map_type_name(&block) },
    location: location
  )
end

#sub(s) ⇒ Object



369
370
371
372
# File 'lib/rbs/types.rb', line 369

def sub(s)
  self.class.new(types: types.map {|ty| ty.sub(s) },
                 location: location)
end

#to_json(*a) ⇒ Object



365
366
367
# File 'lib/rbs/types.rb', line 365

def to_json(*a)
  { class: :tuple, types: types, location: location }.to_json(*a)
end

#to_s(level = 0) ⇒ Object



374
375
376
377
378
379
380
# File 'lib/rbs/types.rb', line 374

def to_s(level = 0)
  if types.empty?
    "[ ]"
  else
    "[ #{types.join(", ")} ]"
  end
end