From 570d7b2c3e2ee39e07548dfe242b684ec794789d Mon Sep 17 00:00:00 2001 From: Victor Shepelev Date: Thu, 14 Dec 2023 23:01:48 +0200 Subject: [DOC] Adjust some new features wording/examples. (#9183) * Reword Range#overlap? docs last paragraph. * Docs: add explanation about Queue#freeze * Docs: Add :rescue event docs for TracePoint * Docs: Enhance Module#set_temporary_name documentation * Docs: Slightly expand Process::Status deprecations * Fix MatchData#named_captures rendering glitch * Improve Dir.fchdir examples * Adjust Refinement#target docs --- variable.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'variable.c') diff --git a/variable.c b/variable.c index de3a3561f8..1a4f919c4c 100644 --- a/variable.c +++ b/variable.c @@ -162,21 +162,21 @@ is_constant_path(VALUE name) * mod.set_temporary_name(string) -> self * mod.set_temporary_name(nil) -> self * - * Sets the temporary name of the module +mod+. This name is used as a prefix - * for the names of constants declared in +mod+. If the module is assigned a - * permanent name, the temporary name is discarded. + * Sets the temporary name of the module. This name is reflected in + * introspection of the module and the values that are related to it, such + * as instances, constants, and methods. * - * After a permanent name is assigned, a temporary name can no longer be set, - * and this method raises a RuntimeError. + * The name should be +nil+ or non-empty string that is not a valid constant + * name (to avoid confusing between permanent and temporary names). * - * If the name given is not a string or is a zero length string, this method - * raises an ArgumentError. + * The method can be useful to distinguish dynamically generated classes and + * modules without assigning them to constants. * - * The temporary name must not be a valid constant name, to avoid confusion - * with actual constants. If you attempt to set a temporary name that is a - * a valid constant name, this method raises an ArgumentError. + * If the module is given a permanent name by assigning it to a constant, + * the temporary name is discarded. A temporary name can't be assigned to + * modules that have a permanent name. * - * If the given name is +nil+, the module becomes anonymous. + * If the given name is +nil+, the module becomes anonymous again. * * Example: * @@ -189,15 +189,20 @@ is_constant_path(VALUE name) * m.set_temporary_name(nil) # => # * m.name #=> nil * - * n = Module.new - * n.set_temporary_name("fake_name") + * c = Class.new + * c.set_temporary_name("MyClass(with description)") * - * n::M = m - * n::M.name #=> "fake_name::M" - * N = n + * c.new # => # * - * N.name #=> "N" - * N::M.name #=> "N::M" + * c::M = m + * c::M.name #=> "MyClass(with description)::M" + * + * # Assigning to a constant replaces the name with a permanent one + * C = c + * + * C.name #=> "C" + * C::M.name #=> "C::M" + * c.new # => # */ VALUE -- cgit v1.2.3