Writing Code for Ruby - Computer Science Programming Basics in Ruby (2013)

Computer Science Programming Basics in Ruby (2013)

Appendix C. Writing Code for Ruby

This appendix describes tools that will make writing Ruby code easier. Utilities that provide syntax highlighting and code indentation make it easier for you to focus on the code you are writing.

C.1 Windows

Most Windows users will prefer to use Edit Plus 2, a text editor that uses syntax highlighting. This utility can be found at http://www.editplus.com. On the main page, click on Download Latest Version and follow the installation instructions. There are also syntax highlighting files on the website, which you will need to download for syntax highlighting in Ruby. These can be found under the Features section. Follow download and install instructions provided by the website.

C.2 Linux

Linux users usually have two choices when it comes to full-featured text editors: emacs and vim. We will discuss vim here, but additional information on emacs can be found on Google by searching for emacs. Vim is a fully customizable text editor that offers out-of-the-box syntax highlighting for nearly every language. To learn how to use vim, type the following in the command line:

$ vimtutor

This text editor will teach you how to use all the commands in vim. You may want to customize vim before jumping in, so in your home directory, create a new file:

$ vim ~/.vimrc

and add the lines:

set number

syntax on

set nowrap

set tabstop=4

Then type :wq and press Enter to save and quit.

For a more comprehensive tutorial, read Learning the vi and Vim Editors by Arnold Robbins, Elbert Hannah, and Linda Lamb (O’Reilly).

C.3 Mac OS X

TextMate is a wonderful (though not free) programming solution. It offers syntax highlighting, macros, and a very intuitive and easy interface. Mac users who do not wish to pay for a text editing suite may also use vim in Terminal (in Applications→Utilities). See the Linux section on getting started with that.

C.4 General Information

§ Ruby files have the extension .rb.

§ To run a Ruby program, either double-click the file or use the command line (assuming the Ruby interpreter executable is in your PATH):

$ ruby program.rb