Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby "gets" does not wait for user input

Tags:

ruby

This is a very silly question, but it doesn't work for me.

I am trying to make the program wait for my input. I tried replacing gets with stdin.gets, and $stdin.gets and when I try gets.chomp I get a nil class exception.

puts "Get works here?"
option = gets
puts option
like image 386
Rohan Dalvi Avatar asked Sep 12 '25 13:09

Rohan Dalvi


1 Answers

To work this,you need to call your .rb file from your command prompt. Like say you save your code in a file called test.rb.

test.rb

puts "Get works here?"
option = gets
puts option

Then run from your command prompt:

C:\Users\arup> ruby test.rb
like image 158
Arup Rakshit Avatar answered Sep 14 '25 04:09

Arup Rakshit