Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!talisker.lacave.net!lacave.net!not-for-mail From: Vahagn Hayrapetyan Newsgroups: comp.lang.ruby Subject: Re: Calling to_enum on a MatchData object Date: Sat, 9 Apr 2011 07:03:23 -0500 Organization: Service de news de lacave.net Lines: 42 Message-ID: References: <840b7dcf34f7c1ae6b2b9d80a6b55b69@ruby-forum.com> NNTP-Posting-Host: bristol.highgroove.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: talisker.lacave.net 1302350621 46633 65.111.164.187 (9 Apr 2011 12:03:41 GMT) X-Complaints-To: abuse@lacave.net NNTP-Posting-Date: Sat, 9 Apr 2011 12:03:41 +0000 (UTC) In-Reply-To: <840b7dcf34f7c1ae6b2b9d80a6b55b69@ruby-forum.com> X-Received-From: This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway X-Mail-Count: 381245 X-Ml-Name: ruby-talk X-Rubymirror: Yes X-Ruby-Talk: Xref: x330-a1.tempe.blueboxinc.net comp.lang.ruby:2579 Thank you for your explanations, I can see now that :each is an inherited method and it had to be ferreted out of the MatchData set of methods. So in order to use an enumerator, an object itself has to define an (:each) method and then an enumerator just augments that. I agree that enum_for(:some_method) is better syntax. This is what I've done just to experiment: def x File.open('screen.css') do |f| while line = f.gets file = line.match(/" (\w* [.] css) "/xms) puts file.class puts file.respond_to?(:each) #false file = line.match(/" (\w* [.] css) "/xms).captures puts file.class #Array puts file.class.instance_methods(false).sort #each is defined e = file.enum_for(:each) #just the default e.each do |entry| #now the enumerator works puts entry end end end end Regarding the regexp: yeah - I was using the universal matcher instead of the dot character by mistake. It worked to fetch the filenames but it was a false positive of course. "It would be nice if the docs specified any parent class to make the hierarchy easy to follow." That would be helpful, definitely. Cheers, Vahagn -- Posted via http://www.ruby-forum.com/.