From: Charles Oliver Nutter on 2 Nov 2009 12:12
On Mon, Nov 2, 2009 at 9:31 AM, Thomas Sevestre <ts(a)tcare.fr> wrote:
> Interesting! I wasn't aware of that.
> Is there any way to make it work?
It is not possible to make it work. I have written on this previously,
but it's a particular ugly wart of Ruby that the $_ and $~ variables
(and related vars like $1, $&, etc) are "special", and only certain
core class methods are able to modify them (in the caller's scope)
while no Ruby code can. It is for this reason that you can't alias and
wrap any of those methods without breaking them.
To be honest, Ruby would be *far* better off if $_ and $~ went away,
since I believe they're overreaching by modifying the caller's scope
without your knowledge.