RE: [Rails] Re: Shorter version for this newbie code...?

I found.

     a = ["a", "b", "c"]
    @contents = a.map{|item| "'" + item + "'"}.to_sentence :connector => ","

Thanks~ ^^

<-----Original Message----->

From: "송치형" <scroco@naver.com>
To: <rubyonrails-talk@googlegroups.com>
Cc:
Sent: 2006-08-21 03:38
Subject: [Rails] Re: Shorter version for this newbie code...?

Hi,

Then... How can remove last ',' easily?

for example, with array

a = ["a", "b", "c"]

  I want to get a string "'a', 'b', 'c'".

but a.map{|item| "'" + item + "',"} gives "'a', 'b', 'c',".

I want to remove last ','.

What is the best way to achieve this?

Thanks.

<-----Original Message----->

From: <dblack@wobblini.net>
To: <rubyonrails-talk@googlegroups.com>
Cc:
Sent: 2006-08-21 03:03
Subject: [Rails] Re: Shorter version for this newbie code...?

Hi --

what about @contents = a.map{|item| "'" + item + "'"}.join(",")
or
@contents = "'" + a.join("','") + "'"

Jeremy

Song, Chi-hyung wrote: