Execute Ruby code in sublime text 2

后端 未结 5 1448
栀梦
栀梦 2020-12-15 03:40

How can I run a Ruby file with ST2 and see the ouput? I thought I should use the build command. But if I have this:

def foobar
  \"hello world\"
end

puts fo         


        
相关标签:
5条回答
  • 2020-12-15 03:42

    enter control + ` (key close to number 1 in keyboard so it will open new window bottom of sublime text, where you can enter ruby code and see result), but make sure you have install ruby correctly and set your path from terminal

    0 讨论(0)
  • 2020-12-15 03:52

    I didn't save the file. That's why it didn't work. To run a file without saving it first (like TextMate) you should try to use the Anypreter plugin.

    0 讨论(0)
  • 2020-12-15 03:56

    For future reference, hope it helps somebody:

    I came here with the same problem. (In Sublime Text 3) I followed the answers:

    • selected ruby extention (bottom right in window)
    • selected in menubar: Tools > Build System > Ruby
    • save the file with a name
    • pressed command + b

    and still saw:

    [Finished in 0.1s]

    In the end the (stuppid) problem was: the console window was only one line big. So I only saw the last line, which is the note:

    [Finished in 0.1s]

    solution: make the console window bigger et voila. I couldn't find any setting for that. So in the end I did that with the mouse Screenshot Sublime Text 3 - cropped

    note the cursor (and ruby extention)

    0 讨论(0)
  • 2020-12-15 03:59

    In summary a Sublime text has an "Automatic" Build System by default (after install) and you should changed it to a ruby or whatever language you use. Save the file and press ctrl + b (on windows) - should run the output into the ST console.

    0 讨论(0)
  • 2020-12-15 04:03

    I'm using windows here, but make sure you have selected the correct build system: "Tools > Build System > Ruby", then just press CTRL+B

    0 讨论(0)
提交回复
热议问题