Having looked at this question, I have the following code:
$/ = "\0"
answer = STDIN.gets
Now I was hoping this would allow the user:
- enter multi-line input ending with a tap Ctrl-D.
- enter a single line input ending with a tap Ctrl-D.
- enter "nothing" completion by tapping Ctrl-D.
However, the behavior that I really see is as follows:
- User can enter multi-line input.
- The user may not enter single line input, unless they press Ctrl-D twice .
- The user can enter "nothing" if he immediately hits Ctrl-D.
So, why is the situation with a single line (i.e. if the user entered some text, but does not have a new line, and then clicked Ctrl-D), two clicks are required Ctrl-D? And why does it work then if the user does not enter anything? (I noticed that if they do not enter anything and fall into Ctrl-D, I do not get an empty string, but the class is nil - I found this when I tried to call .empty?as a result, since it suddenly failed terribly. This is a way to make it also return an empty string, this would be nice. I prefer checking .empty?on ==and don't really want to define .empty?for the class nil.)
. " ", Ruby, 200 . , "" - "". , "\n" s, , .