Hi --

On Wed, 9 Nov 2005, Bil.Kleb / gmail.com wrote:

> How do I shim 1.6 for String.match?

I assume there are answers to the obvious questions (Why not
Regexp#match?  Why not 1.8.x?) so I won't ask them :-)

> I've tried,
>
> unless String::respond_to?(:match)

(Is the :: thing only used by gov't employees? :-)

I think you'd want:

   unless String.instance_methods.include?("match")

>  class String
>   def match(regex)
>    regex.match(self)
>   end
> end
>
> but it doesn't set the group match variables, e.g.,
> $1, $2, and so forth.

They'll get set inside the method, but not beyond.  I think the
rationale for this is that otherwise you'd have no sane way of knowing
whether and when they were getting set:

   re = /(blah)/
   re.match(string)
   some_method(whatever)

   # did some_method do a match operation?  did it reset the
   # capture variables?


David

-- 
David A. Black
dblack / wobblini.net