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屋!
查看全文