Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 3rd, 2007, 03:28 PM
RunesS RunesS is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2007
Posts: 1 RunesS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 32 sec
Reputation Power: 0
Wierd problem with if statements

Hello, first post here...

Well I've just(today) started using Ruby, but it's not my first programming language...

When just playing a bit with the basics, and got a really weird problem, I can't get the if statements to work...

I have this code.

Code:
name = gets()
puts '#{name}'

if name == 'Rune' then
     puts 'hello'
elsif name == 'Casper' then
     puts 'fork'
else
     puts 'it didn't work'
end


I run it and type in Rune, and i get this output:
Code:
Rune
it didn't work


The variable does contain the right string, but it skips to the else code-block... I just can't seem to figure out what's wrong!
I've tried using the case statement, same thing happened, just skips to the else statement... (I've also tried the different syntaxes of the statements)

Please, can someone tell my what's wrong..?

Best regards Rune B

Reply With Quote
  #2  
Old June 3rd, 2007, 08:39 PM
superjacent superjacent is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Location: Melbourne, Australia.
Posts: 9 superjacent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 41 m 5 sec
Reputation Power: 0
Send a message via MSN to superjacent Send a message via Yahoo to superjacent Send a message via Google Talk to superjacent
Try this:
irb(main):002:0> name = gets
steve
=> "steve\n"
irb(main):003:0> name = gets.chomp
steve
=> "steve"

Try using 'gets.chomp' rather than 'gets'. As you see from the above, if only using 'gets' the return value includes the next line character.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > Wierd problem with if statements

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap