V
Vahagn Hayrapetyan
Hi, I have the following snippet of code:
def x
File.open('screen.css') do |f|
while line = f.gets
file = line.match(/"(\w*.css)"/)
puts file.class #MatchData
puts file.methods #to_enum defined
e = file.to_enum
puts e.class #Enumerator
puts e.methods #each method defined
e.each do |entry|:
puts entry
end
end
end
end
The result of the regex operation gets stored in "file" as a MatchData
object. Then I convert it to an Enumerator object, which by all accounts
has an each method defined. Yet when I try to "e.each" here's what I
get:
undefined method `each' for #<MatchData "\"reset.css\"" 1:"reset.css">
(NoMethodError).
Then I check the docs for the MatchData class:
http://www.ruby-doc.org/core/classes/MatchData.html
and find that no, "to_enum" isn't defined. But then I don't understand
why
file.methods lists it, and why no error is generated when I call
file.to_enum.
Help really appreciated.
def x
File.open('screen.css') do |f|
while line = f.gets
file = line.match(/"(\w*.css)"/)
puts file.class #MatchData
puts file.methods #to_enum defined
e = file.to_enum
puts e.class #Enumerator
puts e.methods #each method defined
e.each do |entry|:
puts entry
end
end
end
end
The result of the regex operation gets stored in "file" as a MatchData
object. Then I convert it to an Enumerator object, which by all accounts
has an each method defined. Yet when I try to "e.each" here's what I
get:
undefined method `each' for #<MatchData "\"reset.css\"" 1:"reset.css">
(NoMethodError).
Then I check the docs for the MatchData class:
http://www.ruby-doc.org/core/classes/MatchData.html
and find that no, "to_enum" isn't defined. But then I don't understand
why
file.methods lists it, and why no error is generated when I call
file.to_enum.
Help really appreciated.