How do I save a text file with a Ruby (.rb) file 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.