On Apr 9, 2011, at 8:03 AM, Vahagn Hayrapetyan wrote:
> 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


You are doing lots of unnecessary work there.  Since MatchData#captures
returns an array and Array already defines each, you don't need to create
any enumerator at all to iterate through the #captures array:

> 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
>      file.each do |entry| 
>        puts entry
>      end
>    end
>  end
> end



Gary Wright