How to get multi-line user input in Ruby?

I know this is a very simple question, but my google-fu fails. I want to enter multiple lines in Ruby, since get gives only one line of input. I want to be able to store this multi-line input in a string so that I can output the string to the end of the file. Is there an available command for this? Thanks in advance!

+2
source share
1 answer

Try the following:

$/ = "END"
user_input = STDIN.gets
puts user_input

The user can continue to enter multiple-line input and end his input by entering END. Keep in mind that IRB does not handle this piece of code very well, so make sure you use the actual ruby ​​interpreter.

, user_input END, , . END, , .

+7

Source: https://habr.com/ru/post/1765112/


All Articles