Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute Ruby code in sublime text 2

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 foobar

and then press cmd + shift + b. All I see is

[Finished in 0.1s]

In textmate I could use the cmd + r (run command) and see all the ouput from the ruby script.

I'm I missing something?

like image 916
vermin Avatar asked Jul 10 '12 09:07

vermin


People also ask

How do I run Ruby code in Sublime Text?

Alternatively you can run it right there in Sublime Text. Make sure you're in Ruby mode by clicking on the language selector in the bottom-right corner of the screen. From then on, you can run it right there in Sublime by pressing Tools -> Build, or using the CTRL-B hotkey.

Can Sublime run Ruby?

Results of Ruby scripts in Sublime Text | by Jason Arnold | Medium. Today I learned that you can run Ruby scripts from inside of Sublime Text. Sure, this isn't going to change the world but now I don't have to leave the editor, go to the terminal, and run the file separately.


3 Answers

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.

like image 91
vermin Avatar answered Oct 22 '22 21:10

vermin


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

like image 32
Filipe Miguel Fonseca Avatar answered Oct 22 '22 21:10

Filipe Miguel Fonseca


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)

like image 4
Alphons Avatar answered Oct 22 '22 23:10

Alphons