Jarsen Jarsen - 4 months ago 13x
Ruby Question

One liner in Ruby for displaying a prompt, getting input, and assigning to a variable?

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?


Check out highline:

require "highline/import"
input = ask "Input text: "