Use the split method to do this:
"one,two,three,four".split(',') # ["one","two","three","four"]
If you want to ignore the use of leading / trailing space, use:
"one , two , three , four".split(/\s*,\s*/) # ["one", "two", "three", "four"]
If you want to parse several lines (for example, a CSV file) into separate arrays:
require "csv" CSV.parse("one,two\nthree,four") # [["one","two"],["three","four"]]
Kevin Sylvestre Jan 31 '11 at 4:01 2011-01-31 04:01
source share