Reputation: 11
I'm new to coding and have been learning ruby and javascript recently and whenever I'm practicing ruby and use the gets keyword in sublime text 3 nothing works. I can type stuff in the console but the rest of the program won't run
Upvotes: 0
Views: 307
Reputation: 26778
gets
won't work if you're running the script via the Sublime 'build' command. The reason is that Sublime runs your code in a non-interactive shell.
You will have to run the file with a terminal, like ruby <my_file.rb>
You can see the same result with the following (the gets won't work in either):
# in ruby, gets won't work in a background thread
Thread.new { gets.chomp }
# in bash, gets won't work in a backgrounded process
$ ruby -e "gets.chomp" &
Upvotes: 2