From: "Mauricio Fernández" Date: 2002-12-03T23:47:35+09:00 Subject: Re: Conditional block operations On Tue, Dec 03, 2002 at 10:58:15PM +0900, Roman Rytov wrote: > 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 wanna work it just over not empty lines or lines fitting some pattern. file.readlines.select{ |x| x =~ pattern }.each{ |line| a,b = line.split(pattern) } > > > Anotehr question is about COLLECT; > > myarray.collect {|x| x + ", "} > > I wanna execute only over specific emelents (let's say only odd ones or > all but last). myarray.select{ |x| x % 2 == 1 }.collect{ |x| x + ", " } #.join here ? myarray[0..-1].collect{ |x| x + ", " } # .join ?? > I know how to do both of them in a couple of lines but RUBY impresses my > by its brevity. Will it do it in this case too? > > > Roman Rytov -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com * liw prefers not to have Linus run Debian, because then /me would have to run Red Hat, just to keep the power balance :) -- #Debian