2012-02-17 78 views
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) 
+0

沒有爲STDIN沒有這樣的方法,來看看[此篇](HTTP: //stackoverflow.com/questions/3699134/ruby-stdin-gets-without-showing-chars-on-screen)看如何接受密碼 – 2012-02-17 08:04:59

+0

http://stackoverflow.com/questions/133719/how-可以,我讀-A-passwo rd – nkm 2012-02-17 08:19:58

+0

非常感謝,用highline它是okey! – user1215688 2012-02-17 09:26:24

回答

10

起初

require 'io/console' 

以後紅寶石1.9.3

相關問題