From: Brian Buckley Date: 2006-04-03T21:02:01+09:00 Subject: Re: %w{tomato cheese ham pineapple}.join(', ', ' and ') ------=_Part_27015_12388787.1144065718388 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline One more tweak for the empty array if "" makes sense. class Array def join_sentence case length when 0: "" when 1: self[0] else [self[0..-2].join(", "), self[-1]].join(" and ") end end end On 4/2/06, joey__ wrote: > > class Array > def join_sentence > case length > when 1 > self[0] > when 2 > "#{self[0]} and #{self[1]}" > else > "#{self[0...-1].join(', ')} and #{self[-1]}" > end > end > end > > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_27015_12388787.1144065718388--