Randy Kramer
9/21/2008 11:08:00 PM
On Sunday 21 September 2008 06:37 pm, William James wrote:
> Jody Glidden wrote:
> > 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.
Just for kicks, I managed to modify your approach to make it work (at
least in irb):
"I love guitar playing".split.each {|s| s.capitalize!}.join(" ")
So, it took the addition of each to cause the block to actually do
something, and switching from capitalize to capitalize! (Which, iiuc,
causes the original object to be changed, rather than creating a new
changed object.
Try substituting things like puts "test" in the body of the block to
experiment.
Randy Kramer
--
I didn't have time to write a short letter, so I created a video
instead.--with apologies to Cicero, et.al.