Clean up this Ruby code under DRY principle I've got the following code, which works, but seems repetitive. Under DRY principle, how can I clean this up?

puts "Blurt out a word"
word = gets.chomp
word_list = []
word_list.push word

until word == ""
  word = gets.chomp
  word_list.push word
end

puts word_list.sort
puts "Blurt out a word"
word_list = []
while word_list.last != ""
  word_list &lt;&lt; gets.chomp
end
puts word_list.sort


If you prefer the until:

puts "Blurt out a word"
word_list = []
until word_list.last == ""
  word_list &lt;&lt; gets.chomp
end
puts word_list.sort


You can also do it shorter:

puts "Blurt out a word"
word_list = []
word_list &lt;&lt; gets.chomp until word_list.last == "" 
puts word_list.sort


Remark: The last (empty) line is also returned. To skip the empty line you may use:

puts word_list[0..-2].sort