I'm looking to read in data from the user, however, I do not want the input to show directly on the screen. Rather, I'd like to leave it blank or better yet, obfuscate characters to be input with an astericks.
For example:
print "Password: "
pass = STDIN.gets.chomp
Assuming you are using at least ruby 1.9, you can use the noecho method on IO: http://www.ruby-doc.org/stdlib-2.0/libdoc/io/console/rdoc/IO.html#method-i-noecho
So:
require 'io/console'
print "Password: "
STDIN.noecho(&:gets).chomp
This will not obfuscate the characters, but will simply leave the input terminal blank.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With