From: Ruby Fan Date: 2008-09-22T06:09:52+09:00 Subject: Re: Iterating through a string Stefano Crocco wrote: > Alle Sunday 21 September 2008, Jody Glidden ha scritto: >> If I try the following... >> >> "I love guitar playing".split {|s| s.capitalize}.join(" ") >> >> I would expect it to capitalize the first letter of each word but it >> doesn't seem to work. >> >> Any hints on what I'm doing incorrectly? > > > String#split doesn't take a block, so that the block you pass to it is > ignored. What you wrote is equivalent to > > "I love guitar playing".split.join(" ") > > To do what you want, you need to call map on the array returned by > String#split: > > "I love guitar playing".split.map{|s| s.capitalize}.join(" ") > > I hope this helps > > Stefano Ahh, I understand. I must have missed the map/collect functionality. Thanks. -- Posted via http://www.ruby-forum.com/.