On Apr 17, 6:28 pm, “smc smc” [email protected] wrote:
hello.rb:1: Invalid char \340' in expression hello.rb:1: Invalid char
\241’ in expression
hello.rb:1: Invalid char `\261’ in expression
h-68-164-42-185:~/documents stefan$
do i need to get into irb then out and then do it?
Nope, it looks like the file wasn’t saved as plain text. I’m guessing
you tried saving it from Word, like you said earlier. I don’t know
how to save as plain text in Word, so I’ll show you how to do it
another way.
Open your file in TextEdit. If TextEdit can’t open the old file, it
might be having problems with the MS format, just delete the old one
and start a new file in TextEdit, and enter your ruby code. Make sure
you hit return at the end of your file ( this is just so we can view
it with the cat command later ).
Unless you have converted the file to plain text, TextEdit won’t let
you save it as a “.rb” file. So, first, go to “Format->Make Plain
Text” (if you only see “Make Rich Text”, then it’s already plain
text). If it asks you whether to convert the file to plain text,
click OK. Then save the file as “hello.rb”. TextEdit will probably
pop up with a message saying 'You have used the extension “.rb” at the
end of the name. The standard extension is “.txt”. Click the button
that says “Use .rb”. (
Now, you can check from the command line that your file is actually
plain text, by using the “cat” command.
h-68-164-42-185:~/documents stefan$ cat hello.rb
puts “Hello World”
And now you can run it.
h-68-164-42-185:~/documents stefan$ ruby hello.rb
Hello World
Later on, you might want to consider getting a “real” text editor to
help you write ruby code. They’ll do things that Word & TextEdit
don’t that make it easier to write good code. Features like syntax
highlighting and auto-indentation are two of the ways that “real” text
editors help coders catch errors early on.
I’m not going to tell you which one to use. If you ask any
programmer, anywhere on the web, they’ll tell you which they use, and
why it’s the one you should use. You might want to check out the
wikipedia article (Text editor - Wikipedia), as that
might give you some good leads.
But, I wouldn’t get too sidetracked by looking for an editor.
TextEdit (in plain text mode) should be good enough to get you through
the basic tutorials.