From: Sagy Drucker Date: 2012-12-06T14:58:26+09:00 Subject: Re: Having isues with capitalizing words --20cf3003bcb072aa8804d028c9bf Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Your code won=92t work even after replacing =93or=94 with =93and=94s: Firstly, don=92t use =93||=94 for =93or=94. Simply use =93or=94 command. Secondly, the capture group you defined (\A|\s) will catch only the *first*letter. Hence it will never be =93and=94 , =93an=94 or =93the=94. Ma= ybe just =93a=94 or =93t=94. This will work: *words.gsub!(/\w+/)do |match|* * (match=3D=3D"and" or match=3D=3D"an" or match=3D=3D"the") ? match : mat= ch.capitalize * *end* Enjoy Sagy *From:* phluid61@gmail.com [mailto:phluid61@gmail.com] *On Behalf Of *Matth= ew Kerwin *Sent:* Thursday, December 06, 2012 6:11 AM *To:* ruby-talk ML *Subject:* Re: Having isues with capitalizing words 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!=3D"and" || word!=3D"an" || word!=3D"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/. --=20 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 --20cf3003bcb072aa8804d028c9bf Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable

Yo= ur code won=92t work even after replacing =93or=94 with =93and=94s:<= /p>

Firstly, don=92t use =93|= |=94 for =93or=94. Simply use =93or=94 command.

Secondly, the capture group you defined (\= A|\s) will catch only the first letter. Hence it will never be =93an= d=94 , =93an=94 or =93the=94. Maybe just =93a=94 or =93t=94.

=A0

This will work:

=A0

words.gsub!(/\w+/)do |match|

=A0=A0 (match=3D=3D&qu= ot;and" or match=3D=3D"an" or match=3D=3D"the") ? = match : match.capitalize

end

=A0

Enjoy

Sagy

=A0

From: phluid61@gmail.com [mailto:phluid61@gmail.com] On Behalf Of Matthew Kerwin
Sent: Thursday, December 06, 2012 6:11 AM
To: ruby-talk ML=
Subject: Re: Having isues with capitalizing words

=A0

Try using "and"s= instead of "or"s.

=A0

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 wor= ds.gsub(/(\A|\s)\w/) do |word|
=A0 if(word!=3D"and" || word!= =3D"an" || word!=3D"the")
=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 t= he longest time and I can't figure
it out.

All I want the met= hod 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 ha= ve
tried a million versions of it as well.

Can someone help me ge= t in the right direction with this?

--

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



= =A0

--
=A0 Matthew Kerwin, B.Sc (CompSci) (Hons)
= =A0 http://matt= hew.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

--20cf3003bcb072aa8804d028c9bf--