get a single char of input

suggest change

Unlike gets.chomp this will not wait for a newline.

First part of the stdlib must be included

require 'io/console'

Then a helper method can be written:

def get_char
  input = STDIN.getch
  control_c_code = "\u0003"
  exit(1) if input == control_c_code
  input
end

Its’ imporant to exit if control+c is pressed.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents