instance method
IO#getpass
(?::String) -> ::String
io.getpass(prompt=nil) → string
ext/io/console/console.c
View on GitHub ↗
static VALUE
console_getpass(int argc, VALUE *argv, VALUE io)
{
VALUE str, wio;
rb_check_arity(argc, 0, 1);
wio = rb_io_get_write_io(io);
if (wio == io && io == rb_stdin) wio = rb_stderr;
prompt(argc, argv, wio);
rb_io_flush(wio);
str = rb_ensure(getpass_call, io, puts_call, wio);
return str_chomp(str);
}
Reads and returns a line without echo back. Prints prompt unless it is nil.
The newline character that terminates the read line is removed from the returned string, see String#chomp!.
You must require ‘io/console’ to use this method.
Example
require 'io/console' IO::console.getpass("Enter password:") Enter password: # => "mypassword"