Class: RBS::Types::UntypedFunction

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/types.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(return_type:) ⇒ UntypedFunction

Returns a new instance of UntypedFunction.



1244
1245
1246
# File 'lib/rbs/types.rb', line 1244

def initialize(return_type:)
  @return_type = return_type
end

Instance Attribute Details

#return_typeObject (readonly)

Returns the value of attribute return_type.



1242
1243
1244
# File 'lib/rbs/types.rb', line 1242

def return_type
  @return_type
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



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

def ==(other)
  other.is_a?(UntypedFunction) && other.return_type == return_type
end

#each_param(&block) ⇒ Object



1274
1275
1276
1277
1278
1279
1280
# File 'lib/rbs/types.rb', line 1274

def each_param(&block)
  if block
    # noop
  else
    enum_for :each_param
  end
end

#each_type(&block) ⇒ Object



1266
1267
1268
1269
1270
1271
1272
# File 'lib/rbs/types.rb', line 1266

def each_type(&block)
  if block
    yield return_type
  else
    enum_for :each_type
  end
end

#empty?Boolean

Returns:

  • (Boolean)


1302
1303
1304
# File 'lib/rbs/types.rb', line 1302

def empty?
  true
end

#free_variables(acc = Set.new) ⇒ Object



1248
1249
1250
# File 'lib/rbs/types.rb', line 1248

def free_variables(acc = Set.new)
  return_type.free_variables(acc)
end

#has_classish_type?Boolean

Returns:

  • (Boolean)


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

def has_classish_type?
  return_type.has_classish_type?
end

#has_self_type?Boolean

Returns:

  • (Boolean)


1306
1307
1308
# File 'lib/rbs/types.rb', line 1306

def has_self_type?
  return_type.has_self_type?
end

#hashObject



1332
1333
1334
# File 'lib/rbs/types.rb', line 1332

def hash
  self.class.hash ^ return_type.hash
end

#map_type(&block) ⇒ Object



1252
1253
1254
1255
1256
1257
1258
# File 'lib/rbs/types.rb', line 1252

def map_type(&block)
  if block
    update(return_type: yield(return_type))
  else
    enum_for :map_type
  end
end

#map_type_name(&block) ⇒ Object



1260
1261
1262
1263
1264
# File 'lib/rbs/types.rb', line 1260

def map_type_name(&block)
  UntypedFunction.new(
    return_type: return_type.map_type_name(&block)
  )
end

#param_to_sObject



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

def param_to_s
  "?"
end

#return_to_sObject



1322
1323
1324
# File 'lib/rbs/types.rb', line 1322

def return_to_s
  return_type.to_s(1)
end

#sub(subst) ⇒ Object



1288
1289
1290
1291
1292
# File 'lib/rbs/types.rb', line 1288

def sub(subst)
  return self if subst.empty?

  map_type { _1.sub(subst) }
end

#to_json(state = _ = nil) ⇒ Object



1282
1283
1284
1285
1286
# File 'lib/rbs/types.rb', line 1282

def to_json(state = _ = nil)
  {
    return_type: return_type
  }.to_json(state)
end

#update(return_type: self.return_type) ⇒ Object



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

def update(return_type: self.return_type)
  UntypedFunction.new(return_type: return_type)
end

#with_nonreturn_void?Boolean

Returns:

  • (Boolean)


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

def with_nonreturn_void?
  false
end

#with_return_type(ty) ⇒ Object



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

def with_return_type(ty)
  update(return_type: ty)
end