Ruby Language get a single char of input


Example

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.