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: [email protected]
To: [email protected]
Cc:
Sent: 2006-08-21 03:03
Subject: [Rails] Re: Shorter version for this newbie code…?

Hi –

On Sun, 20 Aug 2006, Daniel H. wrote:

<%= s.name %>,
#ShowType:0x22cd910,#ShowType:0x22cd8d4,

What’s wrong there? And how do I get rid of the comma at the end of the
enumeration in an elegant way? I know there’s join(…), but this as
long as I only get those strange
#ShowType:0x22cd910#ShowType:0x22cd8d4 and so on this doesn’t help
me much. :wink:

Try <%= profile.show_types.join(‘,’) %>

I think he wants to harvest the name attributes, like:

<%= profile.show_types.map {|s| s.name }.join(“,”) %>

David


http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <-----
http://dablog.rubypal.com => D[avid ]A[. ]B[lack’s][ Web]log
Ruby for Rails => book, Ruby for Rails
http://www.rubycentral.org => Ruby Central, Inc.


»õ·Î¿î ±âºÎ ¹®È­ÀÇ ¾¾¾Ñ, ÇØÇǺó
http://happybean.naver.com

–~–~---------~–~----~------------~-------~–~----~
You received this message because you are subscribed to the Google
Groups “Ruby on Rails: Talk” group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~–~—