From: Gennady Bystritksy Date: 2005-01-08T07:49:43+09:00 Subject: Re: what's the Ruby way to do this? Douglas Livingstone wrote: >>>def snippet(thought) >>> thought.split[0..9].join(" ") + "..." >>>end >> >>is more the "Ruby Way" >> > > > Shorter too. > Works differently, though ;-) -- it adds "..." to any result, while the regexp version adds "..." only if a phrase has been truncated. To make it equivalent non-regexp one without using termporary storage, I could come up with the following: def snippet(thought, n = 10) [ thought.split[0, n+1] ].map { |a| a[0, n] + (a[n] && '...').to_a }.join(' ') end Gennady.