Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   Looping Problem (http://www.velocityreviews.com/forums/t858300-looping-problem.html)

Scott Andrechek 06-28-2009 03:56 AM

Looping Problem
 
Hi. I'm new to ruby and i am trying to get a while not loop to occur if
the answer i got from gets wasn't capatalized. This is what i have now:

while not answer3.upcase
puts "WHAT!"
answer3=gets
end

It's not working and i've also tried answer3= .upcase and such. Thanks
in advance for the help.
--
Posted via http://www.ruby-forum.com/.


Christopher Dicely 06-28-2009 04:50 AM

Re: Looping Problem
 
On Sat, Jun 27, 2009 at 8:56 PM, Scott
Andrechek<scottandrechek@gmail.com> wrote:
> Hi. I'm new to ruby and i am trying to get a while not loop to occur if
> the answer i got from gets wasn't capatalized. This is what i have now:
>
> while not answer3.upcase
> =C2=A0puts "WHAT!"
> =C2=A0answer3=3Dgets
> end
>
> It's not working and i've also tried answer3=3D .upcase and such. Thanks
> in advance for the help.



The String#upcase method returns a string which is equal to the string
it is called on with all the letters converted to upper case. If you
want to check that a string has no lowercase letters, you could use
"answer3 =3D=3D answer3.upcase" as your condition. If you want to check
that a string is capitalized (which is slightly different), "answer3
=3D=3D answer3.capitalize" is more likely to be what you want.


Scott Andrechek 06-28-2009 05:01 AM

Re: Looping Problem
 
Thanks alot. It works perfect now :)
--
Posted via http://www.ruby-forum.com/.


Bertram Scharpf 06-28-2009 01:48 PM

Re: Looping Problem
 
Hi,

Am Sonntag, 28. Jun 2009, 13:50:21 +0900 schrieb Christopher Dicely:
> On Sat, Jun 27, 2009 at 8:56 PM, Scott
> Andrechek<scottandrechek@gmail.com> wrote:
> >
> > while not answer3.upcase
> > =A0...
> > end
> >

>=20
> The String#upcase method returns a string [...].
> "answer3 =3D=3D answer3.upcase"


Untested:

class String
def is_upper?
self =3D=3D upcase
end
end

Bertram


--=20
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de



All times are GMT. The time now is 12:35 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57