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.



299
300
301
302
# File 'lib/rbs/types.rb', line 299

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

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



297
298
299
# File 'lib/rbs/types.rb', line 297

def location
  @location
end

#typesObject (readonly)

Returns the value of attribute types.



296
297
298
# File 'lib/rbs/types.rb', line 296

def types
  @types
end

Instance Method Details

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



304
305
306
# File 'lib/rbs/types.rb', line 304

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

#each_type(&block) ⇒ Object



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

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

#free_variables(set = Set.new) ⇒ Object



314
315
316
317
318
319
320
# File 'lib/rbs/types.rb', line 314

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

#hashObject



310
311
312
# File 'lib/rbs/types.rb', line 310

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

#sub(s) ⇒ Object



326
327
328
329
# File 'lib/rbs/types.rb', line 326

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

#to_json(*a) ⇒ Object



322
323
324
# File 'lib/rbs/types.rb', line 322

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

#to_s(level = 0) ⇒ Object



331
332
333
334
335
336
337
# File 'lib/rbs/types.rb', line 331

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