Working on a first plain Ruby script, need help with `join'

I need help in the block to create a csv file of these entries.

the file, abridged:

@verb_index = "

aah v 1 1 @ 1 0 00865776
abacinate v 1 1 @ 1 0 02168378
abandon v 5 4 @ ~ $ + 5 5 02228031 02227741 02076676 00613393 00614057
abase v 1 3 @ ~ + 1 0 01799794
abash v 1 3 @ ~ + 1 0 01792097
.
.
.
zone v 2 3 @ ~ + 2 0 02512150 00332835
zonk_out v 2 2 @ ~ 2 0 00023868 00016855
zoom v 3 3 @ ~ + 3 1 02055521 02056209 01943718
zoom_along v 1 1 @ 1 0 02055521
zoom_in v 1 1 @ 1 0 02153253
"

@verbs_array = @verb_index.split(/\n/)

@verbs_array.each do |n|

n.split
n.join(", ") # fails

How do I output the lines into a verb_index.csv file ?

end

Jesse C. wrote:

n.split
n.join(", ") # fails

Do you want to do n.split.join(", ") ?

On Fri, Jul 11, 2008 at 11:38 AM, Jesse C. [email protected]
wrote:

n.split
n.join(", ") # fails

n.split returns a new object containing the array of split entries
from n. you aren’t assigning this new object to anything, so it is
silently discarded. the object pointed to by n is unchanged. what you
want is something like

a = n.split
a.join(", ")

or more compactly

n.split.join(", ')

martin

عمر ملقب بالثانی wrote:

Jesse C. wrote:

n.split
n.join(", ") # fails

Do you want to do n.split.join(", ") ?

Yes. How do I put them into a CSV file? Thank you.

On Jul 11, 2008, at 3:08 PM, Jesse C. wrote:

Yes. How do I put them into a CSV file? Thank you.

Use FasterCSV (which replaces CSV in the standard lib for Ruby 1.9)

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

Jesse C. wrote:

عمر ملقب بالثانی wrote:

Do you want to do n.split.join(", ") ?

Yes. How do I put them into a CSV file? Thank you.

Supposing you’re reading from stdin or from files passed as argument and
you’re writing to stdout:

ARGF.each { |line| puts line.split.join(’, ') }

If you want to output to file

output_file = open (‘output.cvs’, ‘w’)
ARGF.each { |line| output_file.puts line.split.join(’, ') }

[a beginner in Ruby]