Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Ruby在控制台中创建标头和尾部?_Ruby_Console Application - Fatal编程技术网

如何使用Ruby在控制台中创建标头和尾部?

如何使用Ruby在控制台中创建标头和尾部?,ruby,console-application,Ruby,Console Application,我想为我的脚本构建一个漂亮的控制台界面。我想是这样的: =================== Header information =================== $ user input goes here =================== Trailer information =================== def prompt(stage) puts '============================================' puts

我想为我的脚本构建一个漂亮的控制台界面。我想是这样的:

===================
Header information
===================
$ user input goes here
===================
Trailer information
===================
def prompt(stage)
  puts '============================================'
  puts stage[:head]
  puts '============================================'
  print '$ '
  puts gets.chomp
  puts '============================================'
  puts stage[:tail]
  puts '============================================'
  system("clear") unless system("cls")
end
现在我的代码是这样的:

===================
Header information
===================
$ user input goes here
===================
Trailer information
===================
def prompt(stage)
  puts '============================================'
  puts stage[:head]
  puts '============================================'
  print '$ '
  puts gets.chomp
  puts '============================================'
  puts stage[:tail]
  puts '============================================'
  system("clear") unless system("cls")
end
cource
stage[:tail]
直到用户完成输入后才会打印出来,然后用
system('clear')
清除


是否可以在
获取
后打印内容,但强制用户输入以“$”开头的屏幕行。

Ruby绑定到
诅咒
:。你可以用它构建任意复杂的控制台界面。在诅咒上,你应该使用你已经得到的。通过使用
print
而不是
put
,光标保持在提示符
$
之后。不清楚你不能做什么。