How do I save a text file with a Ruby (.rb) file extension?

I am new to Ruby and am trying to learn from a book. However, I have one problem – it says I should save a file so that it ends with .rb but my Mac only lets me use .rtf so that's what I used. But the next thing I needed to do was open it in Terminal and the command cd /Users/username/ruby didn't work for me. I'm guessing the reason for this is because I didn't use .rb it didn't work.

So my question is: What should I use for writing Ruby in the end of that command, or for saving with the .rb extension?


You could only save as .rtf because the file was rich text. To make it plain text, simply press ⇧ shift-⌘ command-T or go Format > Make Plain Text, then you can save as .rb.

Try not to use TextEdit: there is no syntax highlighting and code completion, not to mention that you have to manually turn off those wrong quotation marks.


What you do is get yourself a proper code editor or IDE. Using TextEdit to write code is a very bad idea. Personally I'd recommend Sublime Text 3 because it has good text highlighting for many different languages, is free (well technically isn't, but for learning like you're doing, not buying a license should be ok), and is pretty lightweight but you should do some research and reach your own conclusions about which code editor or IDE is right for you.