Module: Axn::Internal::ClassName

Defined in:
lib/axn/exceptions.rb

Overview

The name of a value's class, derived WITHOUT dispatching anything the value can override. An error message that names the offending value's class by calling value.class (or inspect) runs the value's own code at the moment the error is being built, so the value can replace the failure being reported with an exception of its own — and one outside StandardError then escapes the rescue StandardError callers map these failures with, which is the escape naming the class is meant to describe. A bound base implementation cannot be intercepted.

Not dispatching is ALL this promises. What it returns is the constant path's own bytes, and a constant may hold non-UTF-8 ones (Object.const_set(:"Caf\xE9", Class.new) is accepted, and Module#to_s hands those bytes back), so interpolating the result into a UTF-8 message can still raise Encoding::CompatibilityError from the reporting itself. A layer writing a class name into prose therefore renders it, and the composition has one owner per question: Internal::RenderedClassName just below for a VALUE's class, which Internal::Rendering.class_name delegates to and which the message paths built ON this file (UnserializableValue#message and UnserializableArgument#message below, Internal::Reflection::Values.describe_key_classes) reach directly; and Internal::Rendering.module_name for a class or module named in its own right, which only callers above this file need. The direction is forced: the reflection and rendering layers require THIS file, so a reference from here up into either would leave a message path NameError-ing under the standalone loads spec/axn/standalone_require_spec.rb pins. The byte half they all compose through, Internal::Text, has no requires of its own and sits below every one of them.

Class Method Summary collapse

Class Method Details

.of(value) ⇒ Object

Module#to_s rather than #name, which is nil for an anonymous class; to_s always returns a String ("#Class:0x…" there).



37
# File 'lib/axn/exceptions.rb', line 37

def self.of(value) = MODULE_TO_S.bind_call(OBJECT_CLASS.bind_call(value))

.of_module(mod) ⇒ Object

The name of a class or module ITSELF, rather than of a value's class — for a message that names a declared type. Same reasoning: a class can define its own to_s, and one that raises would replace the failure being reported.



42
# File 'lib/axn/exceptions.rb', line 42

def self.of_module(mod) = MODULE_TO_S.bind_call(mod)