lines = [
'the brown fox jumped,',
'over the fence,'
]

results = []

lines.each do |line|
  line.chomp!(',')
  words = line.split(' ')
  print "words: "
  p words

  words.inject('') do |accumulator, word|
    accumulator << "#{word} "
    results << "#{accumulator.chomp(' ')},"
    accumulator

  end
end

puts results

--output:--
the,
the brown,
the brown fox,
the brown fox jumped,
over,
over the,
over the fence,

-- 
Posted via http://www.ruby-forum.com/.