From: "Mauricio Fernández" Date: 2005-11-09T07:00:00+09:00 Subject: Re: String#match shim for Ruby 1.6 On Wed, Nov 09, 2005 at 04:02:12AM +0900, Bil.Kleb@gmail.com wrote: > I got the '::' from the IO.read that ts gave me. > > So, then my question becomes, can I create > a shim for 1.8's String#match with pure Ruby? I fear the closest you can get would be class String def match(re,&b) r = re.match(self) eval("lambda{|m| $~ = m}", b).call($~) r end end "foo".match(/foo/) # => # $& # => nil RUBY_VERSION # => "1.6.8" Of course, you can also use Florian's Binding.of_caller to get the environment of the caller and substitute it in the eval, but callcc is expensive [even my my variant, which doesn't use it, is quite expensive and you can only have a trace_func at a time...]. -- Mauricio Fernandez