From: Vahagn Hayrapetyan Date: 2011-04-13T20:14:29+09:00 Subject: Re: Calling to_enum on a MatchData object 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/.