Since I have a Windows machine, I’ve been using Visual Studio Code for all my Ruby work. I had heard stories that doing Ruby development on Windows was a bit of a mission, but I thought I’d at least give it a go before shelling out some serious dollars for a Mac.

Installing Ruby on Windows was pretty straightforward. Quick download and making sure that I could use it on my command line to run simple Ruby programs. I then wanted to get my hands on a text editor that could help me with my Ruby development efforts.

About Visual Studio Code

I’d heard about Visual Studio Code through various different place, plus I used to work for Microsoft so I’m used to their tools. Plus alternatives like Atom are quite big (300MB) compared to Visual Studio Code (32MB).

Code is a text editor that allows you to develop applications for Windows, Mac and Linux. It’s hosted on GitHub and it also supports extensions (I’ll talk about some Ruby specific ones later).

Integrated Command Line and Git

A big thing for me was to have a text editor that had a integrated command line. I don’t mind having to switch tabs all the time, I just wanted things to be lazy and simple.

The integrated terminal opens up in the root of whatever project your working on (Lazy? check!). You can also have multiple terminals open within the editor (Simple? check!).

Code also has built in Git support, meaning that you can track changes in your project and commit them all in one space. There’s a bunch of Git features that Code has that makes life simpler, such as viewing differences in versions and viewing the status of your repositories.

Extensions for Ruby

Code has an extensive extension library (see what I did there?….I didn’t think it was funny either). I’m currently using two extensions for Ruby. The first one is called…..Ruby (not very interesting). This extension provides language and debugging support, such as formatting, intellisense for Ruby and debugging for Rails.

The second one I’m using is Ruby Language Colorization. I like things looking pretty.

Example Workflow

So let’s take it for a test drive and let’s see how easy it is to use Visual Studio Code for Ruby development. I’m going to assume you have Git, Ruby, Code etc. installed so I won’t waste time explaining all of that.

I’ve already set up a project in Code and initialized it with git. As you can see from the screenshot, Code already has the project root ready to go in the terminal:

We can create a new file easily enough by clicking on the new file icon under the project name. I’ve created a file called example.rb and written the following code:

Simple enough code. We ask the user to enter a number to square, pass it as a parameter to our square method and then return the newly squared number back to the user.

Let’s run it! Instead of doing this in a separate terminal, we can use the integrated terminal within the editor like so:

We get the following output, all shown within the editor:

See nice and simple. We can run our program and we didn’t even need to leave the editor! Now if you have a gander towards the left hand side of the editor, you’ll notice a ‘1’ by the Git logo. Let’s have a close look at it:

As we can see, the file is unstaged. We have two options, we can stage and commit the file using the UI, or we can do this properly in the command line. Let’s do things properly and do this through the command line:

Now have a gander at the Source Control panel, we can now see that our file has been staged:

Let’s continue the commit:

All done!

So we’ve created a new program, tested and ran it and pushed it to Git all without leaving the text editor itself! All bloody amazing stuff!

The future

Hopefully this blog post has shown you how Code can make life a lot easier when it comes to simple development tasks, even when dealing with non Microsoft technologies. It’s probably worthwhile to mention that I haven’t tried anything too ambitious with Code yet, such as a Rails project. When I attempt that, I’ll let you know how I get on.