Class: RBS::Types::Block

Inherits:
Object
  • Object
show all
Includes:
_ToJson
Defined in:
lib/rbs/types.rb,
sig/types.rbs

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.

Parameters:

  • location: (loc, nil) (defaults to: nil)
  • type: (function)
  • self_type: (t, nil) (defaults to: nil)
  • required: (boolish)


1396
1397
1398
1399
1400
1401
# File 'lib/rbs/types.rb', line 1396

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

#locationloc? (readonly)

Returns the value of attribute location.

Returns:

  • (loc, nil)


1394
1395
1396
# File 'lib/rbs/types.rb', line 1394

def location
  @location
end

#requiredBoolean (readonly)

Returns the value of attribute required.

Returns:

  • (Boolean)


1392
1393
1394
# File 'lib/rbs/types.rb', line 1392

def required
  @required
end

#self_typet? (readonly)

Returns the value of attribute self_type.

Returns:

  • (t, nil)


1393
1394
1395
# File 'lib/rbs/types.rb', line 1393

def self_type
  @self_type
end

#typefunction (readonly)

Returns the value of attribute type.

Returns:

  • (function)


1391
1392
1393
# File 'lib/rbs/types.rb', line 1391

def type
  @type
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

  • other (Object)

Returns:

  • (Boolean)


1403
1404
1405
1406
1407
1408
# File 'lib/rbs/types.rb', line 1403

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

#map_type {|arg0| ... } ⇒ Block

Yields:

Yield Parameters:

  • arg0 (t)

Yield Returns:

  • (t)

Returns:



1428
1429
1430
1431
1432
1433
1434
# File 'lib/rbs/types.rb', line 1428

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

#sub(s) ⇒ Block

Parameters:

Returns:



1418
1419
1420
1421
1422
1423
1424
1425
1426
# File 'lib/rbs/types.rb', line 1418

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



1410
1411
1412
1413
1414
1415
1416
# File 'lib/rbs/types.rb', line 1410

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