I know this is a really simple question but my google-fu is failing me. I want to get multiple line user input in Ruby, as gets only gives you one line of input. I want to be able to store this multiple line input into a string so i can output the string to the end of a file. Is there a command available to do this? Thanks in advance!
相关问题
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
- reference to a method?
- ruby 1.9 wrong file encoding on windows
- gem cleanup shows error: Unable to uninstall bundl
相关文章
- 放在input的text下文本一直出现一个/(即使还没输入任何值)是什么情况
- Ruby using wrong version of openssl
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- “No explicit conversion of Symbol into String” for
- Segmentation fault with ruby 2.0.0p247 leading to
- How to detect if an element exists in Watir
- Show a different value from an input that what wil
Try this:
The user can then keep entering a multiple line input and ends his input by typing in END. Keep in mind that IRB doesn't handle this code snippet well, so make sure you use the actual ruby interpreter.
Also the user_input stores the final END typed in by the user so you'll need to strip it out. You can also use any other string in the place of END for the user to indicate that they've finished inputting.