From: Pit Capitain Date: 2002-09-24T16:55:39+09:00 Subject: Re: ruby refactoring On 24 Sep 2002, at 11:12, dblack@candle.superlink.net wrote: > (...) one quirky thing about this version is > that if you replace the "if" in the middle of the method with > "unless", you get exactly the same results (at least with the > admittedly ragtag bunch of test cases I ran it on). This is an effect > of the fact that if that test is false, midquote gets flipped (in the > else clause), so the if/unless and else clauses affect each other. Interesting logic :-) You could make the code a little bit clearer, at least for me: def make_parts3(msg) buf = [] last_tag = nil msg.each do |line| spline = line.strip.split(/\s+/) next if spline.empty? tag = /^\s*>/.match(line) ? "quoted" : "unquoted" if (tag != last_tag) buf << [ tag,spline ] last_tag = tag else buf[-1][1].concat spline end end buf end All implementations so far leave the quote in the output. I don' t know if that's the desired behaviour. If you want to get rid of the quote, you could do something like: def make_parts4(msg) buf = [] last_tag = nil msg.each do |line| if /^\s*>/.match(line) tag = "quoted" line = $' else tag = "unquoted" end spline = line.strip.split(/\s+/) next if spline.empty? if (tag != last_tag) buf << [ tag,spline ] last_tag = tag else buf[-1][1].concat spline end end buf end Regards, Pit