Noob alert, please help loops and arrays and string methods

I have a very simple assignment of creating a method to capitalize the
first letter in all words of any given sentence, yes it is a school
assignment, and yes I am an idiot. Anyway I have no idea how to use a
loop to add a string method .capitalize to all objects of an array
please help, I won’t show you my code because I’m sure that all of you
can do this in your sleep.

On Tue, Oct 4, 2011 at 3:11 PM, Sathya L. [email protected]
wrote:

Sorry guys for the top post.

“this is an assignment, please try to do it yourself next time and ask
for
help if you want by posting the code which you write”.split.map { |word|
word.capitalize }.join(" ")

On Tue, Oct 4, 2011 at 11:41 AM, Sathya L. [email protected]
wrote:

please help, I won’t show you my code because I’m sure that all of you
can do this in your sleep.

Which is precisely why you should Show Your Work™.

It’s much easier for you to learn something that way. :slight_smile:


Phillip G.

gplus.to/phgaw | twitter.com/phgaw

A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
– Leibniz

Thanks guys, sorry for not putting this in a sub forum

Previously asked @ Simple program, need help - Ruby - Ruby-Forum

That was the assignment, but what I was actually was doing wrong in the
looping code that I had written, which I apologize for not showing, was
that I forgot to add the method to the class string
class string
def capfirst

It turns out I just forgot to assign the method to the string class. lol
Thanks for that bit of code though, I learnt a lot from it.

On Tue, Oct 4, 2011 at 05:41, Sathya L. [email protected] wrote:

I have a very simple assignment of creating a method to capitalize the
first letter in all words of any given sentence

I have no idea how to use a
loop to add a string method .capitalize to all objects of an array

These are two different things. Do you need to capitalize the first
letters of each word in a sentence, or add a method to all objects
of an array? The first, Mayank showed one way how to do. (Nice and
concise for us seasoned programmers, though maybe not very
n00b-readable.) The second, seems like a rather advanced task for a
self-proclaimed n00b…

-Dave