Ruby中的一个衬里用于显示提示,获取输入并分配给变量? [英] One liner in Ruby for displaying a prompt, getting input, and assigning to a variable?
本文介绍了Ruby中的一个衬里用于显示提示,获取输入并分配给变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我经常发现自己在做以下事情:
Often I find myself doing the following:
print "Input text: "
input = gets.strip
是否有一种优美的方法可以在一排中做到这一点?像这样:
Is there a graceful way to do this in one line? Something like:
puts "Input text: #{input = gets.strip}"
此问题是它在显示提示之前先等待输入.有什么想法吗?
The problem with this is that it waits for the input before displaying the prompt. Any ideas?
推荐答案
查看 highline :>
require "highline/import"
input = ask "Input text: "
这篇关于Ruby中的一个衬里用于显示提示,获取输入并分配给变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文