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.
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_name ⇒ String (readonly)
Returns the value of attribute class_name.
18 19 20 |
# File 'lib/rigor/type/singleton.rb', line 18 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
28 29 30 |
# File 'lib/rigor/type/singleton.rb', line 28 def describe(_verbosity = :short) "singleton(#{class_name})" end |
#erase_to_rbs ⇒ String
32 33 34 |
# File 'lib/rigor/type/singleton.rb', line 32 def erase_to_rbs "singleton(#{class_name})" end |
#hash ⇒ Integer
133 |
# File 'sig/rigor/type.rbs', line 133
def hash: () -> Integer
|
#inspect ⇒ String
44 45 46 |
# File 'lib/rigor/type/singleton.rb', line 44 def inspect "#<Rigor::Type::Singleton #{class_name}>" end |