Jamis Buck wrote:

> The captured subgroup in the regexp is correctly assigned to $1 when
> examined inside the overridden #sub! method, but when checked after
> the invocation of the overridden method, the value of $1 is nil.

A related example of something resembling something I was trying once:

def a
  /abc/.match("abc")
end

def b
  p $~[0]
end

a; b
        => NoMethodError: undefined method `[]' for nil:NilClass

My conclusion was that $~ and its relatives weren¡Çt as global as their
insignia might suggest.

> Why?

I was wondering the same thing but figured that it was desired behavior
as I found no previous discussion of it on the mailing list,
        nikolai

-- 
Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}