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.



1189
1190
1191
1192
1193
# File 'lib/rbs/types.rb', line 1189

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.



1186
1187
1188
# File 'lib/rbs/types.rb', line 1186

def required
  @required
end

#self_typeObject (readonly)

Returns the value of attribute self_type.



1187
1188
1189
# File 'lib/rbs/types.rb', line 1187

def self_type
  @self_type
end

#typeObject (readonly)

Returns the value of attribute type.



1185
1186
1187
# File 'lib/rbs/types.rb', line 1185

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



1195
1196
1197
1198
1199
1200
# File 'lib/rbs/types.rb', line 1195

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

#map_type(&block) ⇒ Object



1218
1219
1220
1221
1222
1223
1224
# File 'lib/rbs/types.rb', line 1218

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



1210
1211
1212
1213
1214
1215
1216
# File 'lib/rbs/types.rb', line 1210

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

#to_json(state = _ = nil) ⇒ Object



1202
1203
1204
1205
1206
1207
1208
# File 'lib/rbs/types.rb', line 1202

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