Discussion:
Array to string
A Berger
2016-08-29 07:11:23 UTC
Permalink
Hi
Whats the most elegant / shortest way to convert an array to a string, like
a=["a","b","c"] # => "abc"

And the best way for
a=[1,2,3,4,5] # => "12345"

Thanks
Berg
Matthew Kerwin
2016-08-29 07:28:40 UTC
Permalink
Post by A Berger
Hi
Whats the most elegant / shortest way to convert an array to a string, like
a=["a","b","c"] # => "abc"
And the best way for
a=[1,2,3,4,5] # => "12345"
Thanks
Berg
​Well, clearly the *best *way would be to create a factory class that
builds expert objects to process the various types of lists to...

Er...

Actually I'd just do this:

the_array.join

Cheers
--
Matthew Kerwin
http://matthew.kerwin.net.au/
timlen tse
2016-08-29 07:29:29 UTC
Permalink
[1,2,3].join #=>"123"
Post by Matthew Kerwin
Post by A Berger
Hi
Whats the most elegant / shortest way to convert an array to a string, like
a=["a","b","c"] # => "abc"
And the best way for
a=[1,2,3,4,5] # => "12345"
Thanks
Berg
​Well, clearly the *best *way would be to create a factory class that
builds expert objects to process the various types of lists to...
Er...
the_array.join
Cheers
--
Matthew Kerwin
http://matthew.kerwin.net.au/
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
Matthew Kerwin
2016-08-29 08:47:18 UTC
Permalink
Post by A Berger
Hi
Whats the most elegant / shortest way to convert an array to a
string, like
a=["a","b","c"] # => "abc"
And the best way for
a=[1,2,3,4,5] # => "12345"
Thanks
Berg
Matthew Kerwin <***@kerwin.net.au>于2016幎8月29日呚䞀 䞋午3:28写道
​​> ​Well, clearly the best way would be to create a factory class that
Post by A Berger
builds expert objects to process the various types of lists to...
Er...
the_array.join
Cheers
[1,2,3].join #=>"123"
Yep, that's why I suggested it.

Cheers!
--
Matthew Kerwin
http://matthew.kerwin.net.au/
Ben Silbernagel
2016-08-29 12:19:16 UTC
Permalink
From what I have read this is not common practice, but this is simple.

["a","b","c"] * ""

#join from what I have read up on is the most common way.
Post by Matthew Kerwin
Post by A Berger
Hi
Whats the most elegant / shortest way to convert an array to a string, like
a=["a","b","c"] # => "abc"
And the best way for
a=[1,2,3,4,5] # => "12345"
Thanks
Berg
​​> ​Well, clearly the best way would be to create a factory class that
Post by A Berger
builds expert objects to process the various types of lists to...
Er...
the_array.join
Cheers
[1,2,3].join #=>"123"
Yep, that's why I suggested it.
Cheers!
--
Matthew Kerwin
http://matthew.kerwin.net.au/
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
--
live life, but live it without regrets. A life given and laid down to
follow Yeshua, is a life worth living, because you will not regret that
choice.
A Berger
2016-08-29 07:47:44 UTC
Permalink
Hi
ok, just thought of complicated each and map, because to_s wasn't what I
wanted.

Factory classes! I know every response contains new things, I have never
heard about :)
Are they used commonly in Ruby?

Thanks
Berg
Matthew Kerwin
2016-08-29 08:43:50 UTC
Permalink
Post by A Berger
Hi
ok, just thought of complicated each and map, because to_s wasn't what I
wanted.
Factory classes! I know every response contains new things, I have never
heard about :)
Are they used commonly in Ruby?
​Indeed no. That was a joke, harking back to my Software Engineering / Java
days. If you're interested, you could start at Wikipedia and work your way
from there: https://en.wikipedia.org/wiki/Software_design_pattern
Post by A Berger
Thanks
Berg
​Cheers.
--
Matthew Kerwin
http://matthew.kerwin.net.au/
A Berger
2016-08-29 19:12:15 UTC
Permalink
Hi
YES - haven't seen the :) ?
Perhaps we should start a new thread with subject "Factor classes"
Have already read the wiki because of your 1st mail.
Should this concept be used in Ruby?

And thanks for short arr * char,
very nice! - Its always worth to ask here!

Cheers
Berg
Samir Arapcic
2016-08-29 07:28:49 UTC
Permalink
Try this

a=["a","b","c"]
b = a.join.to_s

a=[1,2,3,4,5]
b = a.join.to_s
Post by A Berger
Hi
Whats the most elegant / shortest way to convert an array to a string, like
a=["a","b","c"] # => "abc"
And the best way for
a=[1,2,3,4,5] # => "12345"
Thanks
Berg
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
Loading...