How to run a Ruby script in Sublime Text 2 from project root

江枫思渺然 提交于 2019-12-30 12:52:05

问题


I have a Ruby project and I'd like to run the scripts directly from Sublime Text in place of having to run them in the terminal. I'm running Ubuntu 12.04 LTS if that matters at all.

From the terminal I need to be located in the project root to make the script work:

$ ruby path/to/file/file.rb

If I try to run it from where the file is located it fails because they are requiring files from various places in the project.

If I run the script in Sublime Text (Ctrl + Shift + B) it fails the same way as I'm running it from the file location.

How do I do this? I suspect this can be solved with a custom build but I've been unsuccessful until now. Any help appreciated.


回答1:


A build file like this might meet your requirements:

{
  "working_dir": "/full/path/to/project/root/",
  "cmd": ["/full/path/to/ruby/", "$file"],
  "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
  "selector": "source.ruby"
}



回答2:


Depending on your scripts you might want to look into using Package Control and the SublimeREPL Package.

SublimeREPL allows you to have a Ruby Interpreter in a separate tab or window in SublimeText. Running CMD + Shift + B has never been very reliable in SublimeText for Ruby code anyways.

Also, similar answer to similar question: Execute Ruby code in sublime text 2



来源:https://stackoverflow.com/questions/17146970/how-to-run-a-ruby-script-in-sublime-text-2-from-project-root

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!