Class: Rigor::Type::Singleton

Inherits:
Object
  • Object
show all
Includes:
AcceptanceRouter, PlainLattice, ValueSemantics
Defined in:
lib/rigor/type/singleton.rb,
sig/rigor/type.rbs

Overview

The singleton type for a Ruby class or module. Inhabitants are the class object itself (e.g. the constant Foo), not its instances. In RBS this corresponds to singleton(Foo).

Singleton[Foo] and Nominal[Foo] share the same class_name but are NEVER equal; they describe disjoint values (the class object vs. instances of the class).

See docs/type-specification/rbs-compatible-types.md (singleton(T)).

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ValueSemantics

included

Constructor Details

#initialize(class_name) ⇒ Singleton

Returns a new instance of Singleton.

Parameters:

  • class_name (String)

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
# File 'lib/rigor/type/singleton.rb', line 20

def initialize(class_name)
  raise ArgumentError, "class_name must be a String, got #{class_name.class}" unless class_name.is_a?(String)
  raise ArgumentError, "class_name must not be empty" if class_name.empty?

  @class_name = class_name.freeze
  freeze
end

Instance Attribute Details

#class_nameString (readonly)

Returns the value of attribute class_name.

Returns:

  • (String)


18
19
20
# File 'lib/rigor/type/singleton.rb', line 18

def class_name
  @class_name
end

Instance Method Details

#==Boolean

Parameters:

  • other (Object)

Returns:

  • (Boolean)


132
# File 'sig/rigor/type.rbs', line 132

def ==: (untyped other) -> bool

#acceptsAcceptsResult

Parameters:

  • other (Type::t)
  • mode: (accepts_mode)

Returns:



131
# File 'sig/rigor/type.rbs', line 131

def accepts: (Type::t other, ?mode: accepts_mode) -> AcceptsResult

#botTrinary

Returns:



129
# File 'sig/rigor/type.rbs', line 129

def bot: () -> Trinary

#describe(_verbosity = :short) ⇒ String

Parameters:

  • verbosity (Symbol)

Returns:

  • (String)


28
29
30
# File 'lib/rigor/type/singleton.rb', line 28

def describe(_verbosity = :short)
  "singleton(#{class_name})"
end

#dynamicTrinary

Returns:



130
# File 'sig/rigor/type.rbs', line 130

def dynamic: () -> Trinary

#erase_to_rbsString

Returns:

  • (String)


32
33
34
# File 'lib/rigor/type/singleton.rb', line 32

def erase_to_rbs
  "singleton(#{class_name})"
end

#hashInteger

Returns:

  • (Integer)


133
# File 'sig/rigor/type.rbs', line 133

def hash: () -> Integer

#inspectString

Returns:

  • (String)


44
45
46
# File 'lib/rigor/type/singleton.rb', line 44

def inspect
  "#<Rigor::Type::Singleton #{class_name}>"
end

#topTrinary

Returns:



128
# File 'sig/rigor/type.rbs', line 128

def top: () -> Trinary