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: Wed, 13 Apr 2011 06:14:29 -0500 Organization: Service de news de lacave.net Lines: 34 Message-ID: <344464c2400147e5f1dae39f855a89b7@ruby-forum.com> 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 1302693287 64111 65.111.164.187 (13 Apr 2011 11:14:47 GMT) X-Complaints-To: abuse@lacave.net NNTP-Posting-Date: Wed, 13 Apr 2011 11:14:47 +0000 (UTC) In-Reply-To: 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: 381411 X-Ml-Name: ruby-talk X-Rubymirror: Yes X-Ruby-Talk: <344464c2400147e5f1dae39f855a89b7@ruby-forum.com> Xref: x330-a1.tempe.blueboxinc.net comp.lang.ruby:2744 Hi, > I'm not sure what you are referring to because each() is neither defined > nor inherited in the MatchData class. Check the output of: > > md = /h/.match('hello') > puts md.methods.sort > > And Enumerator defines its own each() method. Sorry - I meant to say "enum_for / to_enum" was inherited and had to be ferreted out. The reason why I made this mistake is because of this: o = Object.new e = o.enum_for #No argument given, so :each is implied. No errors! e.next #NoMethodError: undefined method `each' for # o.respond_to?(:each) #false. Aha! My confusion with this stems from line 2 above - that you can define a method using a non-existent method as default argument and not get any error message as a consequence of that. But hey - "Ruby is dynamic and so is human nature", so I think I am going to like this behavior anyway. > You may be confusing Enumer-ator with something you read about > Enumer-able. Exactly! I was mixing them up with regards to "each" and "yield". "The Well-Grounded Rubyist" is a great book though. Thanks again for your help - your examples are excellent. -- Posted via http://www.ruby-forum.com/.