Class: RBS::Types::Block

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location: nil, type:, required:, self_type: nil) ⇒ Block

Returns a new instance of Block.



1354
1355
1356
1357
1358
1359
# File 'lib/rbs/types.rb', line 1354

def initialize(location: nil, type:, required:, self_type: nil)
  @location = location
  @type = type
  @required = required ? true : false
  @self_type = self_type
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



1352
1353
1354
# File 'lib/rbs/types.rb', line 1352

def location
  @location
end

#requiredObject (readonly)

Returns the value of attribute required.



1350
1351
1352
# File 'lib/rbs/types.rb', line 1350

def required
  @required
end

#self_typeObject (readonly)

Returns the value of attribute self_type.



1351
1352
1353
# File 'lib/rbs/types.rb', line 1351

def self_type
  @self_type
end

#typeObject (readonly)

Returns the value of attribute type.



1349
1350
1351
# File 'lib/rbs/types.rb', line 1349

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



1361
1362
1363
1364
1365
1366
# File 'lib/rbs/types.rb', line 1361

def ==(other)
  other.is_a?(Block) &&
    other.type == type &&
    other.required == required &&
    other.self_type == self_type
end

#map_type(&block) ⇒ Object



1386
1387
1388
1389
1390
1391
1392
# File 'lib/rbs/types.rb', line 1386

def map_type(&block)
  Block.new(
    required: required,
    type: type.map_type(&block),
    self_type: self_type ? yield(self_type) : nil
  )
end

#sub(s) ⇒ Object



1376
1377
1378
1379
1380
1381
1382
1383
1384
# File 'lib/rbs/types.rb', line 1376

def sub(s)
  return self if s.empty?

  self.class.new(
    type: type.sub(s),
    required: required,
    self_type: self_type&.sub(s)
  )
end

#to_json(state = nil) ⇒ Object



1368
1369
1370
1371
1372
1373
1374
# File 'lib/rbs/types.rb', line 1368

def to_json(state = nil)
  {
    type: type,
    required: required,
    self_type: self_type
  }.to_json(state)
end