0
My ruby input practice won't work.
In my text editor, I wrote the following: puts "Enter your name" name = gets.chomp puts "Welcome, #{name}" When I execute the code as an .rb file, it displays "Enter your name", but as soon as I do so, it crashes. Can you help me? I have no idea what the problem could be.
6 Respuestas
+ 2
What you posted seems to be correct and worked when I tried it. If it will not set you back too much, Arthur, try exiting and restarting your editor. It's rare but I've had a couple editors freeze up and throw errors with perfectly good code due to other processes clogging up the works so to speak.
+ 1
When you say "it crashes" what error messages are you seeing? What are you using to run your programme?
0
Oh, now I get it. The programme actually does work, but cmd closes anyway after "Welcome, #{name}" is displayed. Can I prevent cmd from closing, even when the programme already has finished?
(I'm sorry about grammar mistakes btw, I'm not a native speaker.)
0
Just add another gets at the bottom of the script. It'll wait there till you press return.
0
Thank you!
0
It seems like you double click the ruby script file.
Instead issue the following command in cmd shell.
ruby filename.rb