From: Alex Gutteridge Date: 2007-10-04T13:23:29+09:00 Subject: Re: opinion on a simple method On 4 Oct 2007, at 13:00, 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? > -- > Posted via http://www.ruby-forum.com/. > How about: File.foreach('\movies.txt') do |l| puts l.split.map{|w| w.capitalize}.join(" ") end Alex Gutteridge Bioinformatics Center Kyoto University