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.



1344
1345
1346
1347
1348
1349
# File 'lib/rbs/types.rb', line 1344

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.



1342
1343
1344
# File 'lib/rbs/types.rb', line 1342

def location
  @location
end

#requiredObject (readonly)

Returns the value of attribute required.



1340
1341
1342
# File 'lib/rbs/types.rb', line 1340

def required
  @required
end

#self_typeObject (readonly)

Returns the value of attribute self_type.



1341
1342
1343
# File 'lib/rbs/types.rb', line 1341

def self_type
  @self_type
end

#typeObject (readonly)

Returns the value of attribute type.



1339
1340
1341
# File 'lib/rbs/types.rb', line 1339

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



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

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

#map_type(&block) ⇒ Object



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

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



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

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



1358
1359
1360
1361
1362
1363
1364
# File 'lib/rbs/types.rb', line 1358

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