gets() not stopping to accept input

R

Rubist Rohit

I am using "Programmers Notepad" to write Ruby code. I tried following
code, but gets() is not waiting to accept the input. The whole program
execution finishes when I run the program.

========= CODE ==========
puts 'Enter your name'
name = gets()
puts 'Hello #{name}'
=========================
 
R

Rubist Rohit

The code I have shown in my original post is from the book: "The Book of
Ruby". I tried double quotes also, but it didn't work.
 
A

Ammar Ali

The code I have shown in my original post is from the book: "The Book of
Ruby". I tried double quotes also, but it didn't work.

STDIN is the default, so it's optional. The double quotes are required
for interpolation to take place. If the variable name = 'Someone'

With double quotesHello Someone

With single quotesHello #{name}

I think the problem is in the way you are running the script. What OS
are you running on and how are you invoking the script?

Regards,
Ammar
 
R

Robert Klemme

The code I have shown in my original post is from the book: "The Book of
Ruby". I tried double quotes also, but it didn't work.

Can you show us a transcript of the console session? On what
operating systems do you work?

Kind regards

robert
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top