Class: Rigor::Type::Singleton
- Inherits:
-
Object
- Object
- Rigor::Type::Singleton
- Includes:
- AcceptanceRouter, 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
- #bot ⇒ Object
- #describe(_verbosity = :short) ⇒ Object
- #dynamic ⇒ Object
- #erase_to_rbs ⇒ Object
-
#initialize(class_name) ⇒ Singleton
constructor
A new instance of Singleton.
- #inspect ⇒ Object
- #top ⇒ Object
Methods included from ValueSemantics
Methods included from AcceptanceRouter
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 ⇒ Object (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
#describe(_verbosity = :short) ⇒ Object
29 30 31 |
# File 'lib/rigor/type/singleton.rb', line 29 def describe(_verbosity = :short) "singleton(#{class_name})" end |
#erase_to_rbs ⇒ Object
33 34 35 |
# File 'lib/rigor/type/singleton.rb', line 33 def erase_to_rbs "singleton(#{class_name})" end |
#inspect ⇒ Object
55 56 57 |
# File 'lib/rigor/type/singleton.rb', line 55 def inspect "#<Rigor::Type::Singleton #{class_name}>" end |