I want this to happen...
z = %w[yeah, cool, mad, awesome, funky]
x = z.implode
x
'yeahcoolmadeawesomefunky'
x = z.implode(', ')
x
'yeah, cool, mad, awesome, funky'
I guess I'll just go write one.
Julian.
z = %w[yeah cool mad awesome funky]
=> ["yeah", "cool", "mad", "awesome", "funky"]
x = z.join(', ')
=> "yeah, cool, mad, awesome, funky"
> Is there are similar thing to the PHP version of implode in ruby?
>
> I want this to happen...
>
> z = %w[yeah, cool, mad, awesome, funky]
>
> x = z.implode
x = z.join
or simply
x = z.to_s
>
> x
>
> 'yeahcoolmadeawesomefunky'
>
> x = z.implode(', ')
x = z.join(', ')
> Is there are similar thing to the PHP version of implode in ruby?
>
> I want this to happen...
>
> z = %w[yeah, cool, mad, awesome, funky]
z = %w[yeah cool mad awesome funky]
Additionally to what the others have already said, you can use the
*-operator here:
x = z * ''
x = z * ', '
--
Florian Frank
Shame there's no corresponding String#/
martin
>Shame there's no corresponding String#/
>
>
Ha, now there is:
class String; alias / split; end
'a,b,c' / ',' # => ['a', 'b', 'c']
This looks strange, though:
'a,b,c' / /,/ # => ['a', 'b', 'c']
--
Florian Frank
class String
def /(val)
self.split(val)
end
end
-austin
--
Austin Ziegler * halos...@gmail.com
* Alternate: aus...@halostatue.ca
On Fri, 9 Sep 2005, Julian Leviston wrote:
> Is there are similar thing to the PHP version of implode in ruby?
>
> I want this to happen...
>
> z = %w[yeah, cool, mad, awesome, funky]
See the other answers for the answer(s), but also, note that the
elements in that array are:
"yeah," "cool," "mad," "awesome," "funky"
i.e., the commas are part of the words (which I think isn't what you
wanted :-)
David
--
David A. Black
dbl...@wobblini.net