Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #2744

Re: Calling to_enum on a MatchData object

From Vahagn Hayrapetyan <vahagnh@gmail.com>
Newsgroups comp.lang.ruby
Subject Re: Calling to_enum on a MatchData object
Date 2011-04-13 06:14 -0500
Organization Service de news de lacave.net
Message-ID <344464c2400147e5f1dae39f855a89b7@ruby-forum.com> (permalink)
References <840b7dcf34f7c1ae6b2b9d80a6b55b69@ruby-forum.com> <e6e43a5fecbaa1960938d453c77314ee@ruby-forum.com> <b5660160be5954fca0117643f7dcb9f1@ruby-forum.com>

Show all headers | View raw


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 #<Object:0x12ed00>
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/.

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Calling to_enum on a MatchData object Vahagn Hayrapetyan <vahagnh@gmail.com> - 2011-04-08 13:19 -0500
  Re: Calling to_enum on a MatchData object 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-08 14:41 -0500
  Re: Calling to_enum on a MatchData object 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-08 14:21 -0500
  Re: Calling to_enum on a MatchData object 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-08 20:09 -0500
  Re: Calling to_enum on a MatchData object Vahagn Hayrapetyan <vahagnh@gmail.com> - 2011-04-09 07:03 -0500
    Re: Calling to_enum on a MatchData object 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-09 13:18 -0500
      Re: Calling to_enum on a MatchData object Vahagn Hayrapetyan <vahagnh@gmail.com> - 2011-04-13 06:14 -0500
    Re: Calling to_enum on a MatchData object Gary Wright <gwtmp01@mac.com> - 2011-04-09 14:25 -0500
      Re: Calling to_enum on a MatchData object 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-09 17:17 -0500
        Re: Calling to_enum on a MatchData object Vahagn Hayrapetyan <vahagnh@gmail.com> - 2011-04-13 06:28 -0500
          Re: Calling to_enum on a MatchData object Gary Wright <gwtmp01@mac.com> - 2011-04-13 22:44 -0500
  Re: Calling to_enum on a MatchData object 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-09 14:02 -0500
    Re: Calling to_enum on a MatchData object Robert Klemme <shortcutter@googlemail.com> - 2011-04-13 06:45 -0500
      Re: Calling to_enum on a MatchData object Vahagn Hayrapetyan <vahagnh@gmail.com> - 2011-04-14 11:13 -0500
    Re: Calling to_enum on a MatchData object Vahagn Hayrapetyan <vahagnh@gmail.com> - 2011-04-13 06:25 -0500

csiph-web