K
Kless
Why when is showed an array into a variable , it is showed with all
characters followed?
characters followed?
Why when is showed an array into a variable , it is showed with all
characters followed?
Why when is showed an array into a variable , it is showed with all
characters followed?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
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
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.