Class: Konpeito::TypeChecker::Types::NativeModuleType

Inherits:
Type
  • Object
show all
Defined in:
lib/konpeito/type_checker/types.rb

Overview

NativeModule type - module with methods but no instance state Marked with @native annotation in RBS Can be included in classes to mix in methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Type

#eql?, #subtype_of?, #union?, #untyped?

Constructor Details

#initialize(name, methods = {}, native_array_fields: {}) ⇒ NativeModuleType

Returns a new instance of NativeModuleType.

Parameters:

  • Module name

  • (defaults to: {})

    Method name -> signature

  • (defaults to: {})

    field_name -> { element_type:, size: }



1291
1292
1293
1294
1295
# File 'lib/konpeito/type_checker/types.rb', line 1291

def initialize(name, methods = {}, native_array_fields: {})
  @name = name.to_sym
  @methods = methods
  @native_array_fields = native_array_fields
end

Instance Attribute Details

#methodsObject (readonly)

Returns the value of attribute methods.



1286
1287
1288
# File 'lib/konpeito/type_checker/types.rb', line 1286

def methods
  @methods
end

#nameObject (readonly)

Returns the value of attribute name.



1286
1287
1288
# File 'lib/konpeito/type_checker/types.rb', line 1286

def name
  @name
end

#native_array_fieldsObject (readonly)

Returns the value of attribute native_array_fields.



1286
1287
1288
# File 'lib/konpeito/type_checker/types.rb', line 1286

def native_array_fields
  @native_array_fields
end

Instance Method Details

#==(other) ⇒ Object



1307
1308
1309
1310
# File 'lib/konpeito/type_checker/types.rb', line 1307

def ==(other)
  return false unless other.is_a?(NativeModuleType)
  name == other.name
end

#hashObject



1312
1313
1314
# File 'lib/konpeito/type_checker/types.rb', line 1312

def hash
  name.hash
end

#lookup_method(method_name) ⇒ Object

Look up a method by name



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

def lookup_method(method_name)
  @methods[method_name.to_sym]
end

#lookup_native_array_field(field_name) ⇒ Object

Look up a NativeArray field by name



1303
1304
1305
# File 'lib/konpeito/type_checker/types.rb', line 1303

def lookup_native_array_field(field_name)
  @native_array_fields[field_name.to_sym]
end

#to_sObject



1316
1317
1318
# File 'lib/konpeito/type_checker/types.rb', line 1316

def to_s
  "NativeModule(#{name})"
end