Re: Show elements of array separated
- From: Kless <jonas.esp@xxxxxxxxxxxxxx>
- Date: Sat, 30 Aug 2008 04:45:30 -0700 (PDT)
Thanks! I was too complicated:
irb(main):001:0> foo = ['a', 'b', 'c']
=> ["a", "b", "c"]
irb(main):002:0> s = ''
=> ""
irb(main):003:0> foo.each {|x| s += x.to_s + ', '}
=> ["a", "b", "c"]
irb(main):004:0> puts s[0..-3]
a, b, c
=> nil
On Aug 30, 12:33 pm, Robert Klemme <shortcut...@xxxxxxxxxxxxxx> wrote:
On 30.08.2008 10:09, Kless wrote:
Why when is showed an array into a variable , it is showed with all
characters followed?
---------------
foo = ['a', 'b', 'c']
puts "the content is: #{foo}" # => the content is: abc
---------------
I'm supposed that is because at the first it converts the array into a
string. But is there any way of show the elements of array separated?
irb(main):001:0> foo = %w{a b c}
=> ["a", "b", "c"]
irb(main):002:0> foo.to_s
=> "abc"
irb(main):003:0> foo.join ", "
=> "a, b, c"
irb(main):004:0>
Kind regards
robert
.
- Follow-Ups:
- Re: Show elements of array separated
- From: Robert Klemme
- Re: Show elements of array separated
- References:
- Re: Show elements of array separated
- From: Robert Klemme
- Re: Show elements of array separated
- Prev by Date: Re: Show elements of array separated
- Next by Date: Re: Show elements of array separated
- Previous by thread: Re: Show elements of array separated
- Next by thread: Re: Show elements of array separated
- Index(es):