Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #2579
| From | Vahagn Hayrapetyan <vahagnh@gmail.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Re: Calling to_enum on a MatchData object |
| Date | 2011-04-09 07:03 -0500 |
| Organization | Service de news de lacave.net |
| Message-ID | <e6e43a5fecbaa1960938d453c77314ee@ruby-forum.com> (permalink) |
| References | <840b7dcf34f7c1ae6b2b9d80a6b55b69@ruby-forum.com> |
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/.
Back to comp.lang.ruby | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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