I have a small program that I'm working on that at one point I would like the user to be able to input a potentially multiline response.
I've found the example with
$/ = "END"
user_input = STDIN.gets
puts user_input
But this makes all inputs require the END keyword, which I would only need for the one input.
How can I produce a multi-line input for just the one input?
IO#gets
has an optional parameter that allows you to specify a separator. Here's an example:
puts "Enter Response"
response = gets.chomp
puts "Enter a multi line response ending with a tab"
response = gets("\t\n").chomp
Output:
Enter Response
hello
Enter a multi line response ending with a tab
ok
how
is
this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With