From: Shannon Fang Date: 2002-12-03T23:11:31+09:00 Subject: Re: Conditional block operations Hi, >From: "Roman Rytov" >Reply-To: ruby-talk@ruby-lang.org >To: ruby-talk@ruby-lang.org (ruby-talk ML) >Subject: Conditional block operations >Date: Tue, 3 Dec 2002 22:58:15 +0900 > >Is there a way to filter results of EACH or COLLECT functions? Let's say >in > >file.each do |line| > a, b = line.split(pattern) >End I think for this case, the easist way might be file.each do |line| a, b = line.split(pattern) if line !~ /^\s*$/ end But for the next one, I have no idea. I think it has something related to array.each and array.each_index, because in collect, the |x| seems is the element itself, not the index. For example. > >myarray.collect {|x| x + ", "} > myarray.each_index do |i| myarray[i]+=", " if i%2 end Shannon _________________________________________________________________ MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. http://join.msn.com/?page=features/virus