Lloyd Linklater wrote: > I am trying to find the better way to do things ruby style. I needed to > make a method that would read in a file of movie titles and capitalize > each word. > > "this is a string".capitalize just gets the first word, so I did this: > > File.open('\movies.txt') do |f| > while line = f.gets > s = "" > line.split(/ /).each {|one_word| s += one_word.capitalize + ' '} > puts s.chop > end > end > > Is there a cleaner or more "rubyish" way to do this? File.open("data.txt") do |file| file.each() do |line| line.each(" ") do |word| print word.capitalize end end end --input:-- the Bourne ultimatum harry Potter and the Order of the phoenix mission impossible --output:-- The Bourne Ultimatum Harry Potter And The Order Of The Phoenix Mission Impossible -- Posted via http://www.ruby-forum.com/.