Gets() not stopping to accept input

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}'

···

=========================

--
Posted via http://www.ruby-forum.com/.

Unless you are specifying a file name on the command line, you probably
want this to read from the console. For that, you need STDIN.gets.

Also, the string substitution in your third line will only happen if you
use double quotes. So, I think you want:

  puts 'Enter your name'
  name = STDIN.gets
  puts "Hello #{name}"

···

Rubist Rohit <passionate_programmer@hotmail.com> wrote:

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}'

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

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.

···

--
Posted via http://www.ruby-forum.com/.

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 quotes

puts "Hello #{name}"

Hello Someone

With single quotes

puts 'Hello #{name}'

Hello #{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

···

On Wed, Nov 17, 2010 at 9:45 AM, Rubist Rohit <passionate_programmer@hotmail.com> wrote:

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

Kind regards

robert

···

On Wed, Nov 17, 2010 at 8:45 AM, Rubist Rohit <passionate_programmer@hotmail.com> wrote:

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.

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/