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(type:, required:, self_type: nil) ⇒ Block

Returns a new instance of Block.



1312
1313
1314
1315
1316
# File 'lib/rbs/types.rb', line 1312

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

Instance Attribute Details

#requiredObject (readonly)

Returns the value of attribute required.



1309
1310
1311
# File 'lib/rbs/types.rb', line 1309

def required
  @required
end

#self_typeObject (readonly)

Returns the value of attribute self_type.



1310
1311
1312
# File 'lib/rbs/types.rb', line 1310

def self_type
  @self_type
end

#typeObject (readonly)

Returns the value of attribute type.



1308
1309
1310
# File 'lib/rbs/types.rb', line 1308

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



1318
1319
1320
1321
1322
1323
# File 'lib/rbs/types.rb', line 1318

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

#map_type(&block) ⇒ Object



1341
1342
1343
1344
1345
1346
1347
# File 'lib/rbs/types.rb', line 1341

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



1333
1334
1335
1336
1337
1338
1339
# File 'lib/rbs/types.rb', line 1333

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

#to_json(state = _ = nil) ⇒ Object



1325
1326
1327
1328
1329
1330
1331
# File 'lib/rbs/types.rb', line 1325

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