From: eregontp@... Date: 2019-07-06T13:44:47+00:00 Subject: [ruby-core:93577] [Ruby master Bug#11304] [PATCH] Kernel.global_variables should observe $~. Issue #11304 has been updated by Eregon (Benoit Daloze). `$1` - `$N` (there can be more than 9 of them) are treated specially by the parser. In fact, the only way they can work is special treatment by the parser, because there is potentially an infinite number of them. And that's probably why aliasing them is also forbidden: ``` > alias $ONE $1 SyntaxError: (eval):2: can't make alias for the number variables ``` The other Regexp global variables, except `$~`, can be considered "computed" global variables, i.e., they don't need to be actually set and can just be derived from `$~`. Finally, all Regexp global variables are not actually global, they are thread-local and frame-local. So I think this is mostly a documentation bug, `$1-$N` are special and are actually never defined/registered as global variables (because there is an unbounded number of them), while the rest are. I think it make sense for Kernel#global_variables to return all global variables that were actually defined/registered, but not `$1-$N` since they never are defined/registered. ---------------------------------------- Bug #11304: [PATCH] Kernel.global_variables should observe $~. https://bugs.ruby-lang.org/issues/11304#change-79157 * Author: 0x0dea (D.E. Akers) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- The added complexity does impact performance, but the difference is negligible, and the method should return what it says it does. ---Files-------------------------------- global_variables_captures.patch (1.85 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: