Writing an array in a file in ruby -


this question has answer here:

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

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -