On Thu, Sep 29, 2011 at 3:19 PM, Trevor Harker
<koolaidmancometh / gmail.com> wrote:

> I need some help with a simple program to capitalize the first letter of
> each word in a sentence.

> class Array
> =A0def title_format (title)
> =A0 =A0puts title.split(" ").each{|element| print
> element.capitalize!}.join(" ")
> =A0 =A0return title_format
> =A0end
> end

> title.title_format
>
> Help would be greatly appreciated. This is the error i get:
>
> sentence_caps.rb:18: undefined method `title_format' for "please help me
> with my program":String (NoMethodError)

Which is exactly right -- 'title' is a string and there's no such method.
But you can add one:

class String
   def title_format
      self.split.each{|element| element.capitalize! }.join(" ")
   end
end

puts "what the heck".title_format  #=3D> What The Heck

You definitely don't want the `print` and `puts` inside your method,
and in your example you're trying to return the method itself, which
is bound to end badly  :-)

HTH,
--=20
Hassan Schroeder ------------------------ hassan.schroeder / gmail.com
http://about.me/hassanschroeder
twitter: @hassan