123456789_123456789_123456789_123456789_123456789_

Class: RBS::Types::Block

Relationships & Source Files
Inherits: Object
Defined in: lib/rbs/types.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(type:, required:, self_type: nil) ⇒ Block

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1299

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

Instance Attribute Details

#required (readonly)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1296

attr_reader :required

#self_type (readonly)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1297

attr_reader :self_type

#type (readonly)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1295

attr_reader :type

Instance Method Details

#==(other)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1305

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

#map_type(&block)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1328

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

#sub(s)

[ GitHub ]

  
# File 'lib/rbs/types.rb', line 1320

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

#to_json(state = _ = nil)

[ GitHub ]

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

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