Your code wont work even after replacing or with ands:
Firstly, dont use || for or. Simply use or command.
Secondly, the capture group you defined (\A|\s) will catch only the
firstletter. Hence it will never be and , an or the. Maybe
just a or t.
This will work:
- (match==“and” or match==“an” or match==“the”) ? match :
From: [email protected] [mailto:[email protected]] *On Behalf Of
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 [email protected] wrote:
So, this is a method I have made:
words.gsub(/(\A|\s)\w/) do |word|
if(word!=“and” || word!=“an” || word!=“the”)
I have been trying to solve this for the longest time and I can’t figure
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 K., B.Sc (CompSci) (Hons)
“You’ll never find a programming language that frees
you from the burden of clarifying your ideas.” - xkcd