Ruby $stdin.gets without showing chars on screen

前端 未结 6 2083
北海茫月
北海茫月 2020-12-30 00:21

I want to ask users to type in a password, but i dont want the chars to appear on screen as they type.

How do I do this in Ruby?

6条回答
  •  遥遥无期
    2020-12-30 00:52

    If you're on a system with stty:

    `stty -echo`
    print "Password: "
    pw = gets.chomp
    `stty echo`
    puts ""
    

提交回复
热议问题