Class: Rigor::Type::Singleton
- Inherits:
-
Object
- Object
- Rigor::Type::Singleton
- 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
-
#class_name ⇒ String
readonly
Returns the value of attribute class_name.
Instance Method Summary collapse
- #== ⇒ Boolean
- #accepts ⇒ AcceptsResult
- #bot ⇒ Trinary
- #describe(_verbosity = :short) ⇒ String
- #dynamic ⇒ Trinary
- #erase_to_rbs ⇒ String
- #hash ⇒ Integer
-
#initialize(class_name) ⇒ Singleton
constructor
A new instance of Singleton.
- #inspect ⇒ String
- #top ⇒ Trinary
Methods included from ValueSemantics
Constructor Details
#initialize(class_name) ⇒ Singleton
Returns a new instance of Singleton.
21 22 23 24 25 26 27 |
# File 'lib/rigor/type/singleton.rb', line 21 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_name ⇒ String (readonly)
Returns the value of attribute class_name.
19 20 21 |
# File 'lib/rigor/type/singleton.rb', line 19 def class_name @class_name end |
Instance Method Details
#== ⇒ Boolean
132 |
# File 'sig/rigor/type.rbs', line 132
def ==: (untyped other) -> bool
|
#accepts ⇒ AcceptsResult
131 |
# File 'sig/rigor/type.rbs', line 131
def accepts: (Type::t other, ?mode: accepts_mode) -> AcceptsResult
|
#describe(_verbosity = :short) ⇒ String
29 30 31 |
# File 'lib/rigor/type/singleton.rb', line 29 def describe(_verbosity = :short) "singleton(#{AnonymousClassName.display(class_name)})" end |
#erase_to_rbs ⇒ String
33 34 35 36 37 |
# File 'lib/rigor/type/singleton.rb', line 33 def erase_to_rbs return "untyped" if AnonymousClassName.match?(class_name) "singleton(#{class_name})" end |
#hash ⇒ Integer
133 |
# File 'sig/rigor/type.rbs', line 133
def hash: () -> Integer
|
#inspect ⇒ String
47 48 49 |
# File 'lib/rigor/type/singleton.rb', line 47 def inspect "#<Rigor::Type::Singleton #{class_name}>" end |