为什么不能使用类IO的实例方法noecho?

时间:2012-02-17 07:54:52

标签: ruby passwords

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)

1 个答案:

答案 0 :(得分:10)

起初

require 'io/console'

以后的Ruby 1.9.3