From: Belorion Date: 2005-01-08T06:51:37+09:00 Subject: Re: what's the Ruby way to do this? Sorry to post again so soon after my last post -- my reply box lost focus and enter sent the message instead of a newline... Anyway... > Admittedly, his words don't carry as much weight as yours, > but I think they make a lot of sense. Note where he says that > regular expressions can replace "many lines of code", a practice > of which he seems to approve. Please forgive him, if not me, > Belorian. > > "If you have never worked with regular expressions before, > they probably look anything but regular". > > How true that is! I am not as familiar with Ruby-style > regular expressions as I would like to be, since I've done > much more programming in Awk, which has less powerful ones. > I see now that I could have made it shorter (and I wouldn't > be surprised if Florian Gross could make it "yet shorter"): > > def snippet(thought) > thought.match(/(\S+(\s+|$)){0,10}/)[0]+($'>""?"...":"") > end I did not mean to imply regular expressions are in poor form. They are quite powerful, and I think Ruby would be crippled without them. Rather, I was of the opinion that the other solutions were more approriate for the simplicity of the problem, and that *always* using regular expressions can complicate matters that don't need complicating. One of the things I love about Ruby the most is the simplicity of the solutions you can come up with.