From: dblack@... Date: 2002-09-24T21:44:48+09:00 Subject: Re: ruby refactoring Hi -- On Tue, 24 Sep 2002, Pit Capitain wrote: > 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" My little "un" trick was somewhat whimsical :-) I do admittedly tend to avoid using the ternary operator in Ruby -- not on deeply principled grounds, but on the purely aesthetic grounds that to my eyes it jumps out as a C idiom. (NOTE: I'm not trying to talk people out of using it -- just explaining my not having done so :-) > if (tag != last_tag) > buf << [ tag,spline ] > last_tag = tag > else > buf[-1][1].concat spline > end > end > buf > end Yes, much nicer, consolidating the tags/flags. > 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: [code] I was just going for duplicating Joe's output -- not sure what the eventually purpose is. David -- David Alan Black | Register for RubyConf 2002! home: dblack@candle.superlink.net | November 1-3 work: blackdav@shu.edu | Seattle, WA, USA Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com