From: "Eregon (Benoit Daloze)" Date: 2012-07-29T23:52:34+09:00 Subject: [ruby-core:46861] [ruby-trunk - Feature #6802] String#scan should have equivalent yielding MatchData Issue #6802 has been updated by Eregon (Benoit Daloze). prijutme4ty (Ilya Vorontsov) wrote: > Though I suggest that using a special method here is more clear. > So what'd you say about String#each_match and Regexp#each_match I did indeed somewhat expected String#scan to yield a MatchData object, instead of $~.captures. I'm in favor of String#each_match, it might be a nice addition and the name is clear, but the naming is different from the usual regexp methods on String, and it might not be worth to add a method (I agree $~ is not the prettiest thing around). I think Regexp#each_match does not convey well what it does though. ---------------------------------------- Feature #6802: String#scan should have equivalent yielding MatchData https://bugs.ruby-lang.org/issues/6802#change-28536 Author: prijutme4ty (Ilya Vorontsov) Status: Open Priority: Normal Assignee: Category: Target version: Ruby should have method to obtain not an array of arrays but of MatchData objects. It can help in obtaining named groups: pattern = /x: (?\d+) y:(?\d+)/ polygon = [] text.scan_for_pattern(pattern){|m| polygon << Point.new(m[:x], m[:y]) } Not to break existing code we need unique name. Ideas? May be #each_match -- http://bugs.ruby-lang.org/