Gets and chomp method question

P

paul.denlinger

I'm working through the "Gets and chomp method" section of Learn to
Program on http://pine.fm/LearnToProgram/?Chapter=04

I have a problem. I have entered the strings:
puts 'Hello there, and what\'s your name?'
name = gets
puts 'Your name is ' + name + '? What a lovely name!'
puts 'Pleased to meet you, ' + name + '. :)'
into the text editor, and when I run it, it of course runs up to the
second line. At this stage, I'm supposed to get a question, "What's
your name?" and respond by typing in my name.

When I run it, the command box opens, and just stays there. I have
tried typing my name in there, but nothing happens, and I cannot get
the code to continue running.

Where am I supposed to type in my name, and what am I supposed to type
to get the code running through the remaining lines of code?

Thank you.
 
J

Justin Collins

I'm working through the "Gets and chomp method" section of Learn to
Program on http://pine.fm/LearnToProgram/?Chapter=04

I have a problem. I have entered the strings:
puts 'Hello there, and what\'s your name?'
name = gets
puts 'Your name is ' + name + '? What a lovely name!'
puts 'Pleased to meet you, ' + name + '. :)'
into the text editor, and when I run it, it of course runs up to the
second line. At this stage, I'm supposed to get a question, "What's
your name?" and respond by typing in my name.

When I run it, the command box opens, and just stays there. I have
tried typing my name in there, but nothing happens, and I cannot get
the code to continue running.

Where am I supposed to type in my name, and what am I supposed to type
to get the code running through the remaining lines of code?

Thank you.

Where are you running the program from? Inside some IDE? From the
command line? In Windows?

-Justin
 
J

Justin Collins

Justin said:
Where are you running the program from? Inside some IDE? From the
command line? In Windows?

-Justin

Nevermind, I see you are running Scintilla and I don't know anything
about that! :)

-Justin
 
W

William James

I'm working through the "Gets and chomp method" section of Learn to
Program on http://pine.fm/LearnToProgram/?Chapter=04

I have a problem. I have entered the strings:
puts 'Hello there, and what\'s your name?'
name = gets
puts 'Your name is ' + name + '? What a lovely name!'
puts 'Pleased to meet you, ' + name + '. :)'
into the text editor, and when I run it, it of course runs up to the
second line. At this stage, I'm supposed to get a question, "What's
your name?" and respond by typing in my name.

When I run it, the command box opens,

You ought to be running it from the command-line interpreter.
The IDE is not part of Ruby.
and just stays there. I have
tried typing my name in there, but nothing happens, and I cannot get
the code to continue running.

Where am I supposed to type in my name, and what am I supposed to type
to get the code running through the remaining lines of code?

Thank you.

Above the code that you typed, this appears:

What actually happens is that gets just sits there,
reading what you type until you press Enter.
 
G

Guillaume Benny

=20

=20
Nevermind, I see you are running Scintilla and I don't know anything
about that! :)
=20

Hi,

I've never used Scintilla myself but I tried to run your program.

It seems Scintilla has a small splitter on the right. If you drag it to =
the
left, this is the place where your program will write with puts... And =
it's
also there that you type your input (for gets). You have to ignore the
command prompt window that will start... (The splitter can also be at =
the
bottom depending on the options...)

You won't see anything before you type if you leave your program that =
way.
This is because Ruby will wait for more text before printing it because =
it's
more efficient this way. So you can do this to force Ruby to write the =
text
before you wait for the user input:

puts 'Hello there, and what\'s your name?'
STDOUT.flush
name =3D gets
puts 'Your name is ' + name + '? What a lovely name!'
puts 'Pleased to meet you, ' + name + '. :)'=20

You normally don't need that outside Scintilla...

Hope this helps. Good luck!

Guillaume
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

chomp 5
CIN Input #2 gets skipped, I don't understand why. 1
Problem with 'chomp' 8
Logic Problem with BigInteger Method 2
Chomp 4
Easy question about gets 4
gets() not stopping to accept input 3
utf8 and chomp 13

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top