From: Nikolai Weibull Date: 2005-08-25T05:09:55+09:00 Subject: Re: ruby way for piece of code Alexandru Popescu wrote: > > def prepare_content(new_content) > > updated_content = "" > > new_content.each do |line| > > if line =~ /^tags:\s+/i > > $'.split(/\s+/).each{ |t| updated_content << " [[#{t} => #{t}]]" } > > updated_content << "\n" > > else > > updated_content << line > > end > > end > > updated_content > > end > > > > your code is messy, > I have posted again the spec as it seems I haven't succeed to be clear > from the beginning. Sorry. OK, so how about the following then: def prepare_content(new_content) updated_content = "" new_content.each do |line| if line =~ /^tags:\s+/i $'.split(/\s+/).each do |token| if token =~ /\[\[.* => .*\]\]/ updated_content << " " << token else updated_content << " [[#{t} => #{t}]]" end end updated_content << "\n" else updated_content << line end end updated_content end (Why, and how?, are you processing the document for tag-expansion multiple times in this way?), nikolai -- Nikolai Weibull: now available free of charge at http://bitwi.se/! Born in Chicago, IL USA; currently residing in Gothenburg, Sweden. main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}