From: "David A. Black" Date: 2009-06-22T10:32:12+09:00 Subject: Re: regular expression gurus--help! Hi -- On Mon, 22 Jun 2009, Harry Kakueki wrote: > On Sun, Jun 21, 2009 at 9:26 PM, Sebastian > Hungerecker wrote: >> >>>> "abcdefghijkl".scan(/(.)(?=(..))/).map(&:join) >> => ["abc", "bcd", "cde", "def", "efg", "fgh", "ghi", "hij", "ijk", "jkl"] >> >> HTH, >> Sebastian >> >> > > I am not the OP, but thanks for that solution. > I learned more about regular expressions and relearned something about scan. > > It did not work on my machine so I changed it to this. > p "abcdefghijkl".scan(/(.)(?=(..))/).map{|x| x.join} > > Is this map(&:join) using 1.9? Yes. In general, &obj in that position triggers the use of obj.to_proc as the code block for the method call, and in 1.9 there's a built-in Symbol#to_proc method. David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Now available: The Well-Grounded Rubyist (http://manning.com/black2) "Ruby 1.9: What You Need To Know" Envycasts with David A. Black http://www.envycasts.com