Ruby $stdin.gets 在屏幕上不显示字符 [英] Ruby $stdin.gets without showing chars on screen

查看:33
本文介绍了Ruby $stdin.gets 在屏幕上不显示字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要求用户输入密码,但我不希望字符在他们输入时出现在屏幕上.

I want to ask users to type in a password, but I don't want the chars to appear on screen as they type.

如何在 Ruby 中执行此操作?

How do I do this in Ruby?

推荐答案

这种用户交互有一个宝石:高线.

There is a gem for such user interaction: highline.

password = ask("Password:  ") { |q| q.echo = false }

甚至:

password = ask("Password:  ") { |q| q.echo = "*" }

这篇关于Ruby $stdin.gets 在屏幕上不显示字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆