From: Joe Van Dyk Date: 2005-02-05T07:14:47+09:00 Subject: Re: iteration the ruby way On Sat, 5 Feb 2005 07:05:51 +0900, Navindra Umanee wrote: > Hi, > > I have a question about The Ruby Way. Pickaxe gives the following > example for using iterators in Ruby: > > a = [ "a", "b", "c" ] > a.each {|x| print x, " -- " } > > This outputs: > > a -- b -- c -- > > But what if I want to print "a -- b -- c"? What's the proper Ruby way > of doing that? Is there some way of detecting the last element? I > mean, obviously I can do it with a for/while loop or something... > > Thanks, > Navin. > This probably isn't what you're looking for... but: puts a.join(" -- ")