trying 2 learn <lists / ruby-forum.com> wrote:

> 1. You used .upcase!, and maybe you were just providing an example, but
> doesn't that make every letter capital, not just the 1st one? Wouldn't
> .capitalize! be more appropriate?

Quite so.  I'm trying to teach you the concepts involved, without
handing you too much of a ready-made solution.

> 2. If I am not mistaken, I believe the square brackets refer to an
> array.  My intention for the program to react with a varying amount of
> words at a time.

Right... but you want the response to be a string.  So, you have turn
it back into a string before you're done.  I think you've already used
the method you need, in a previous try; now you just need to bring it
back in.  It's much more obvious when you use multiple words.

> 3. I read your blog post, and if I understand the bang(!) correctly it
> actually modifies the string of text for the entire method.

Right.  It modifies the string of text, whereas "upcase" (with no
bang) returns a modified *copy* of it.  In real life analogy, "upcase"
would a person that you show a slip of paper, and he copies down the
contents in uppercase on a new slip and gives that to you.  It's up to
you to put that with the rest of your slips (i.e., record it in a
variable), versus just letting it drop to the floor.  By contrast,
"upcase!" takes your slip of paper, erases each lowercase letter and
replaces it with its uppercase version, and puts the slip back on the
table with the rest of your slips.

(I would have said that upcase! "hands you back your original slip",
but that's exactly the oversimplification that my blog post was
warning about.  It's more like he reads it to you if there were any
changes, else he says nothing, and it's up to you to record the
response (or lack thereof) or ignore it (the usual course of action).)

> In this
> context, using the ! for capitalize would modify the array

Technically, modify each element (at least, those needing mods), but
yes, I think you've got the basic idea.

> so that every
> value passed through would be capitalized. This is why you said the
> .capitalize comes before the .split, because if it were the other way
> around you would only capitalize the 1st word.  Correct?

"before" is how you already had it, as x.capitalize.split.  You want
to split it first, then capitalize each word (except "little words",
which get different treatment, and even then, capitalize it if it's
the first, but I think we can leave that for later), then put it all
back together.

-Dave

-- 
Dave Aronson, the T. Rex of Codosaurus LLC,
secret-cleared freelance software developer
taking contracts in or near NoVa or remote.
See information at http://www.Codosaur.us/.