From: Shannon Fang Date: 2002-12-04T00:26:17+09:00 Subject: Re: Conditional block operations file.grep? I checked that grep is a method of Enumerable. is it suitable for file? if so, it is a class method or instance method? Tks. Shannon >From: Emmanuel Touzery >Reply-To: ruby-talk@ruby-lang.org >To: ruby-talk@ruby-lang.org (ruby-talk ML) >Subject: Re: Conditional block operations >Date: Tue, 3 Dec 2002 23:44:50 +0900 > >Emmanuel Touzery wrote: > >>Shannon Fang wrote: >> >>> >>>I think for this case, the easist way might be >>> >>>file.each do |line| >>> a, b = line.split(pattern) if line !~ /^\s*$/ >>>end >> >> >>grep could help, unfortunately I don't know if it can be negated (eg "all >>but the matches"). >> >>emmanuel > >actually \S is "non whitespace character", so this is ok: > >file.grep /^\S+$/ do |line| > a, b = line.split pattern >end > >emmanuel >-- > >"If someone breaks into my house and steals my CDs, >who calls the cops, me or the music industry? >If it's me, then that's my property." --Ruben Safir _________________________________________________________________ Add photos to your e-mail with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail