print "Enter your password: "
pass = STDIN.noecho(&:gets)
puts "Your password is #{pass}!"
输出:
Enter your password: input.rb:2:in `<main>': undefined method `noecho' for #<IO:<STDIN>> (NoMethodError)
答案 0 :(得分:10)
起初
require 'io/console'
以后的Ruby 1.9.3