From: Bill Guindon Date: 2004-09-19T08:13:18+09:00 Subject: Re: Method improvement request .-- On Sun, 19 Sep 2004 06:29:43 +0900, Charles Hixson wrote: > I'm sure there must be a more idiomatic+efficient way to do this, but I > can't figure it out. Any suggestions? Might be easier if you could show a sample of what you're starting with, and what you'd like it to become. If the sample is large, you can always paste it into codepaste (http://www.codepaste.org), and just put the link to it in the email > Also, I'm not sure all of the tests are necessary. Many of them were > added to avoid "Nil class does not implement..." messages. Is there a > better approach? yes, those still drive me nuts too, but I'm learning :) > yield a if a and a.length > 0 this can be written as... yield a if a unless a.empty? it won't get to the 'unless' if 'a' is nil, so it dodges the missing method error. > return "" unless chunk.respond_to?("[]") you can avoid this by forcing the issue... chunk = [] << chunk chunk.flatten! now chunk is an Array no matter what. could be an empty one, or could contain useless objects, but it's an Array ;) Also... I think parse2 and parse3 can be combined into something like this: p2 = p1.split(/(\.\.\.|--)/) p2.delete('--') p2.delete('...') p2.each {|p3| yield p3} if you can change your editor from tabs to 2 spaces, you're code will hold up better in the emails. -- Bill Guindon (aka aGorilla)