Why should the String keep track of the “pos” if the string has been mutated? In the code that I am trying to convert, if the string is modified, the code itself is responsible for resetting the \G position. IMO, the functions which prepend should invalidate the matchpos (e.g., nil).
-a
···
–
austin ziegler
Sent from my Treo
“Austin Ziegler” austin@halostatue.ca writes:
Why should the String keep track of the “pos” if the string has been
mutated? In the code that I am trying to convert, if the string is
modified, the code itself is responsible for resetting the \G
position. IMO, the functions which prepend should invalidate the
matchpos (e.g., nil).
That’s a solution, though as Nobu Nakada pointed out the whole idea of
having the String keep track of “pos” at all is flawed – since it is
not thread safe.
Also, String#index and an extended Regexp#match that takes an index
allow the user to manage “pos” themselves in however they see fit.