5
print "Enter your password: "
pass = STDIN.noecho(&:gets)
puts "Your password is #{pass}!"
OUTPUT:为什么不能使用类IO的实例方法noecho?
Enter your password: input.rb:2:in `<main>': undefined method `noecho' for #<IO:<STDIN>> (NoMethodError)
没有为STDIN没有这样的方法,来看看[此篇](HTTP: //stackoverflow.com/questions/3699134/ruby-stdin-gets-without-showing-chars-on-screen)看如何接受密码 – 2012-02-17 08:04:59
http://stackoverflow.com/questions/133719/how-可以,我读-A-passwo rd – nkm 2012-02-17 08:19:58
非常感谢,用highline它是okey! – user1215688 2012-02-17 09:26:24