退出鞋子应用程序打破了我的循环!我怎么能阻止这个?

时间:2013-02-26 05:55:02

标签: ruby loops shoes

我有一个等待用户输入字符的command_line(shell)loop。根据用户输入的内容,会发生不同的事情,但循环将一直持续到用户键入“退出”。对于一个命令,我希望打开一个鞋子应用程序。打开工作正常,但当我关闭它时,循环中断并且过程结束。我不希望这个过程结束。它看起来像这样......

def mainLoop()
  loop do
    print "Input word: "
    word = gets.chomp.split(' ')
    if word.length == 0
      launchShoesApp(word[0])
    end

    ...

  end
end

def create_gui(graph)
  Shoes.app { button "Push me" }
end

关闭Shoes.app GUI后,整个过程将关闭。我该如何防止这种情况?

1 个答案:

答案 0 :(得分:0)

我宁愿建议在不同的文件中分离命令行ruby脚本代码和Shoes脚本代码 例如:

#command-line.rb
def mainLoop()
 loop do
  print "Input word: "
  word = gets.chomp.split(' ')
  if word.length == 0
   #launchShoesApp(word[0])
   Process.spawn("ruby shoes-gui.rb") 
   # this will spawn up a process (opening your shoes app) without blocking this ruby script.
  end
 end  
end

#shoes-gui.rb
require 'green_shoes'
Shoes.app { button "Push me" }

确保两个文件都在同一个文件夹中。还要确保你已经安装了'green_shoes'宝石。如果你对green_shoes不满意并且只想使用红鞋,你可以改变系统命令

from:
'ruby shoes-gui.rb'
to:
'yourpath/to/shoes shoes-gui.rb'

一般情况下,你会发现在家里可执行的鞋子/用户名/ .shoes / federales / shoes如果你使用的是linux,而在某些地方使用C驱动器(如果是在Windows上)。

这应该最有效(我在我的机器上测试过)。希望它有帮助:)

相关问题