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.



372
373
374
375
# File 'lib/rbs/types.rb', line 372

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

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



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

def location
  @location
end

#typesObject (readonly)

Returns the value of attribute types.



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

def types
  @types
end

Instance Method Details

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



377
378
379
# File 'lib/rbs/types.rb', line 377

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

#each_type(&block) ⇒ Object



412
413
414
415
416
417
418
# File 'lib/rbs/types.rb', line 412

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

#free_variables(set = Set.new) ⇒ Object



387
388
389
390
391
392
393
# File 'lib/rbs/types.rb', line 387

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

#hashObject



383
384
385
# File 'lib/rbs/types.rb', line 383

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

#map_type(&block) ⇒ Object



427
428
429
430
431
432
433
434
435
436
# File 'lib/rbs/types.rb', line 427

def map_type(&block)
  if block
    Tuple.new(
      types: types.map {|type| yield type },
      location: location
    )
  else
    enum_for :map_type
  end
end

#map_type_name(&block) ⇒ Object



420
421
422
423
424
425
# File 'lib/rbs/types.rb', line 420

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

#sub(s) ⇒ Object



399
400
401
402
# File 'lib/rbs/types.rb', line 399

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

#to_json(state = _ = nil) ⇒ Object



395
396
397
# File 'lib/rbs/types.rb', line 395

def to_json(state = _ = nil)
  { class: :tuple, types: types, location: location }.to_json(state)
end

#to_s(level = 0) ⇒ Object



404
405
406
407
408
409
410
# File 'lib/rbs/types.rb', line 404

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