Class: Rigor::Type::Singleton
- Inherits:
-
Object
- Object
- Rigor::Type::Singleton
- Includes:
- AcceptanceRouter, PlainLattice, ValueSemantics
- Defined in:
- lib/rigor/type/singleton.rb
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` and `Nominal` 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 ⇒ Object
readonly
Returns the value of attribute class_name.
Instance Method Summary collapse
- #describe(_verbosity = :short) ⇒ Object
- #erase_to_rbs ⇒ Object
-
#initialize(class_name) ⇒ Singleton
constructor
A new instance of Singleton.
- #inspect ⇒ Object
Methods included from ValueSemantics
Methods included from AcceptanceRouter
Methods included from PlainLattice
Constructor Details
#initialize(class_name) ⇒ Singleton
Returns a new instance of Singleton.
22 23 24 25 26 27 28 |
# File 'lib/rigor/type/singleton.rb', line 22 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 ⇒ Object (readonly)
Returns the value of attribute class_name.
20 21 22 |
# File 'lib/rigor/type/singleton.rb', line 20 def class_name @class_name end |
Instance Method Details
#describe(_verbosity = :short) ⇒ Object
30 31 32 |
# File 'lib/rigor/type/singleton.rb', line 30 def describe(_verbosity = :short) "singleton(#{class_name})" end |
#erase_to_rbs ⇒ Object
34 35 36 |
# File 'lib/rigor/type/singleton.rb', line 34 def erase_to_rbs "singleton(#{class_name})" end |
#inspect ⇒ Object
46 47 48 |
# File 'lib/rigor/type/singleton.rb', line 46 def inspect "#<Rigor::Type::Singleton #{class_name}>" end |