Writing an array in a file in ruby -
this question has answer here:
- ruby combining array 1 string 2 answers
how write array in ruby keeping elements of array in same line?
e.g.
a= ["tom", "jerry"] puts
gives:
tom jerry
but need have:
tom, jerry
thank help!
you can use join
method on array this.
a= ["tom", "jerry"] puts a.join(", ")
interestingly, can multiply array string wish separate elements by:
a= ["tom", "jerry"] puts * ", "
both of above give same output:
tom, jerry
Comments
Post a Comment