From: Matthew Kerwin Date: 2012-12-06T13:10:53+09:00 Subject: Re: Having isues with capitalizing words --e89a8ff1ca52e8897504d02748c5 Content-Type: text/plain; charset=ISO-8859-1 Try using "and"s instead of "or"s. On 6 December 2012 14:02, JD KF wrote: > So, this is a method I have made: > > def title(words) > words.gsub(/(\A|\s)\w/) do |word| > if(word!="and" || word!="an" || word!="the") > word.upcase > else > word.downcase > end > end > end > > I have been trying to solve this for the longest time and I can't figure > it out. > > All I want the method to do is take in a string and capitalize every > word except for "and" and "an" and "the". > > The above will not do it and I really don't understand why. I have > tried a million versions of it as well. > > Can someone help me get in the right direction with this? > > -- > Posted via http://www.ruby-forum.com/. > > -- Matthew Kerwin, B.Sc (CompSci) (Hons) http://matthew.kerwin.net.au/ ABN: 59-013-727-651 "You'll never find a programming language that frees you from the burden of clarifying your ideas." - xkcd --e89a8ff1ca52e8897504d02748c5 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Try using "and"s instead of "or"s.


On 6 December 2012 14:02, JD KF <lists@ruby-forum.com> wrote:
So, this is a method I have made:

def =A0title(words)
=A0 =A0 words.gsub(/(\A|\s)\w/) do |word|
=A0 if(word!=3D"and" || word!=3D"an" || word!=3D"t= he")
=A0 =A0 =A0 word.upcase
=A0 else
=A0 =A0 =A0 word.downcase
=A0 end
=A0 =A0 end
end

I have been trying to solve this for the longest time and I can't figur= e
it out.

All I want the method to do is take in a string and capitalize every
word except for "and" and "an" and "the".

The above will not do it and I really don't understand why. =A0I have tried a million versions of it as well.

Can someone help me get in the right direction with this?

--
Posted via http://= www.ruby-forum.com/.




-- =A0 Matthew Kerwin, B.Sc (CompSci) (Hons)
=A0 http://matthew.kerwin.net.au/
= =A0 ABN: 59-013-727-651

=A0 "You'll never find a programming language that frees
= =A0 you from the burden of clarifying your ideas." - xkcd
--e89a8ff1ca52e8897504d02748c5--