I attempted to capture input using 'gets,' but it includes all characters, including those that I deleted. For instance, take a look at the following program.
puts "Enter your name : "
STDOUT.flush
name=gets
p name
When requesting input, the printed output includes the characters I entered, even those that I am in the process of deleting.
Here is the output you could notice.
>ruby hi.rb
Enter your name :
raja
"rajaagoa\n"
>Exit code: 0
I understand that 'gets' captures all the characters, leading to the current output. However, I would like to only display the characters I input. In the given example, if I enter 'raja,' I want only 'raja' to be printed but unfortunately it prints all the characters which I deleted while I input. Is there a way to accomplish this?
I also experimented with the code below, but it exhibited the same behavior.
page_name = ""
while (char = STDIN.getc) != "\n"
page_name += char
end