From: ts Date: 2000-12-08T22:24:21+09:00 Subject: [ruby-talk:6937] Re: Some performance issues >>>>> "B" == Ben Tilly writes: B> OK, this has me curious. How was this done internally? When ruby compile a script and find $&, $', ... it will create a node BACK_REF (node NTH_REF for $1, $2, ...) When this node is executed, it retrieve the information stored in the variable $~ (which contain the string used for the regexp (stored via rb_str_new4()), and registers) and extract the part of the string corresponding to $&, ... $~ (like $_) make reference to a local (and thread based) variable, i.e. when ruby call a def the first 2 local variables are $_ and $~ B> for it. So it looks like it is lazy. But when I try to B> modify the string before having to work out $` and $' I B> am unable to find a way to mess up $' and $`. (Which is When ruby want to modify a string, it first verify if this string is associated with another string (like in the regexp case) and if this is true it make first a copy of the string before modifying it (see rb_str_modify() and rb_str_independent() in string.c). Guy Decoux