Module: Rigor::Type::AnonymousClassName
- Defined in:
- lib/rigor/type/anonymous_class_name.rb
Overview
#319 — the spelling of a class that Ruby created without a name: the Class.new do ... end /
Module.new do ... end form away from constant-write position, which owns whatever its block body defines
but has no constant to be keyed by.
Inference::AnonymousMetaClass decides WHICH call sites get one and what goes in the key; this module owns
the spelling, because the two places a name reaches a human live here. #<Label:key> is deliberately
unspellable as a Ruby constant path, so a synthetic name can never collide with a real class in the
discovery tables.
Both renderings drop the key. describe keeps only the label (#<Class>) because the key is a file
position — reproducing it would pin every assert_type fixture and precision snapshot to a line number.
erase_to_rbs answers untyped: the name is not valid RBS, and emitting it from rigor sig-gen would
produce a signature file that does not parse.
Constant Summary collapse
- PREFIX =
"#<"
Class Method Summary collapse
-
.build(label, key) ⇒ Object
build("Class", "lib/a.rb:3:17") #=> "#<Class:lib/a.rb:3:17>". -
.display(class_name) ⇒ Object
The display form: the label alone, key dropped.
- .match?(class_name) ⇒ Boolean
Class Method Details
.build(label, key) ⇒ Object
build("Class", "lib/a.rb:3:17") #=> "#<Class:lib/a.rb:3:17>"
24 25 26 |
# File 'lib/rigor/type/anonymous_class_name.rb', line 24 def build(label, key) "#{PREFIX}#{label}:#{key}>" end |
.display(class_name) ⇒ Object
The display form: the label alone, key dropped.
33 34 35 36 37 |
# File 'lib/rigor/type/anonymous_class_name.rb', line 33 def display(class_name) return class_name unless match?(class_name) "#{PREFIX}#{class_name.delete_prefix(PREFIX).split(':', 2).first}>" end |
.match?(class_name) ⇒ Boolean
28 29 30 |
# File 'lib/rigor/type/anonymous_class_name.rb', line 28 def match?(class_name) class_name.is_a?(String) && class_name.start_with?(PREFIX) end |