Class: Types::Interface

Inherits:
Object
  • Object
show all
Includes:
Generic
Defined in:
lib/types/interface.rb

Overview

Represents an RBS interface type.

“‘ruby type = Types::Interface.new(“MyInterface”) type.to_rbs # => “_MyInterface” type.to_s # => “Interface(MyInterface)” “`

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Generic

#|

Constructor Details

#initialize(name) ⇒ Interface

Returns a new instance of Interface.



20
21
22
# File 'lib/types/interface.rb', line 20

def initialize(name)
	@name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



25
26
27
# File 'lib/types/interface.rb', line 25

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



51
52
53
# File 'lib/types/interface.rb', line 51

def == other
	other.is_a?(Interface) && @name == other.name
end

#composite?Boolean

Returns:



28
29
30
# File 'lib/types/interface.rb', line 28

def composite?
	true
end

#hashObject



56
57
58
# File 'lib/types/interface.rb', line 56

def hash
	@name.hash
end

#to_rbsObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/types/interface.rb', line 38

def to_rbs
	if @name.include?("::")
		# For nested interfaces like "MyLibrary::MyInterface", return "MyLibrary::_MyInterface"
		parts = @name.split("::")
		parts[-1] = "_#{parts[-1]}"
		parts.join("::")
	else
		# For simple interfaces like "MyInterface", return "_MyInterface"
		"_#{@name}"
	end
end

#to_sObject



33
34
35
# File 'lib/types/interface.rb', line 33

def to_s
	"Interface(#{@name})"
end