tags:

views:

33

answers:

1

Is there a way to implode an array in Ruby to combine all elements into one string?

Example Array:

@arr = ['<p>Hello World</p>', '<p>This is a test</p>']

Example Output:

<p>Hello World</p> <p>This is a test</p>

Thanks in advance!

+6  A: 

Use the Array#join method (the argument to join is what to insert between the strings - in this case a space):

@arr.join(" ")
sepp2k