Forum: Ruby new

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
new
poison tooth (Guest)
on 2007-04-17 19:23
(Received via mailing list)
Im just learning ruby and im stuck the guide im using says

"Your first program
Congratulations! Now that you have made it this far, you are ready to
start writing programs.
Hello World
Grab a text editor and type in the following:

puts "Hello World"

Save the file as hello.rb and run it by typing
ruby hello.rb"

i've tried that more than once and it says the out is:

"irb(main):001:0> ruby hello.rb
NameError: undefined local variable or method `hello' for main:Object
       from (irb):1
irb(main):002:0> "

the guide never said what word processor should i use
i tried TextEdit.app but it fussed about the .rb
so i used Microsoft word and this is what it does...

Any tips?
Glen Holcomb (Guest)
on 2007-04-17 19:29
(Received via mailing list)
You need to type "ruby hello.rb" from the command line rather than
inside of
irb.

On 4/17/07, poison tooth <fixxie.wits@gmail.com> wrote:
>
> the guide never said what word processor should i use
>
--
"Hey brother christian with your high and mighty errand, Your actions
speak
so loud, I can't hear a word you're saying."

-Greg Graffin (Bad Religion)
A764542dba6b8ec3749b7dd9ae8d8e62?d=identicon&s=25 Shawn B. (nephish)
on 2007-04-17 19:31
(Received via mailing list)
if your in a linux computer, you may need this at the beginning of your
program

#!/usr/bin/env ruby

or

#!/usr/bin/ruby

also may need to make the file executatble by

chmod a+x /path/to/your/program.rb

hth
A764542dba6b8ec3749b7dd9ae8d8e62?d=identicon&s=25 Shawn B. (nephish)
on 2007-04-17 19:32
(Received via mailing list)
oops, did not read your email well enough.

dont use MS word, use notepad or something
MS word puts a lot of formatting stuff in the file
hth.

sk
Mark Volkmann (Guest)
on 2007-04-17 19:34
(Received via mailing list)
On Apr 17, 2007, at 12:22 PM, poison tooth wrote:

> Save the file as hello.rb and run it by typing
> ruby hello.rb"
>
> i've tried that more than once and it says the out is:
>
> "irb(main):001:0> ruby hello.rb
> NameError: undefined local variable or method `hello' for main:Object
>       from (irb):1
> irb(main):002:0> "

Try running "ruby hello.rb" from a Terminal window (on a Mac) instead
of from irb.
If you want to run it from irb, enter "load 'hello.rb'".

> the guide never said what word processor should i use
> i tried TextEdit.app but it fussed about the .rb
> so i used Microsoft word and this is what it does...
>
> Any tips?

You can use any text editor. TextEdit should be fine, but there are
many better choices. I see you're on a Mac. Check out TextMate.
Morton Goldberg (Guest)
on 2007-04-17 21:00
(Received via mailing list)
On Apr 17, 2007, at 1:22 PM, poison tooth wrote:

> Save the file as hello.rb and run it by typing
> i tried TextEdit.app but it fussed about the .rb
> so i used Microsoft word and this is what it does...
>
> Any tips?

Since you mention TextEdit, I presume you are on a Mac. Also, since
you mention irb, I presume you are familiar with Terminal. Here is an
easy way to run a Ruby script in Terminal. After writing your hello
script in TextEdit save it as hello.rb. Now in terminal at a fresh
prompt, type "ruby " (without the quotes and remember to include the
space after "ruby"). Now drag hello.rb into to Terminal and hit
return. The text "Hello World" should appear.

Regards, Morton
Morton Goldberg (Guest)
on 2007-04-17 21:23
(Received via mailing list)
On Apr 17, 2007, at 2:59 PM, Morton Goldberg wrote:

>> puts "Hello World"
>>
> fresh prompt, type "ruby " (without the quotes and remember to
> include the space after "ruby"). Now drag hello.rb into to Terminal
> and hit return. The text "Hello World" should appear.

Also, there is one more possible source of trouble. TextEdit must be
in Plain Text mode when you save a Ruby script. If it's in Rich Text
mode, hit cmnd-shift-T to change the mode before you save.

Regards, Morton
smc smc (Guest)
on 2007-04-18 00:23
(Received via mailing list)
oh ok
i think i know where i made my mistake
thanks
smc smc (Guest)
on 2007-04-18 00:29
(Received via mailing list)
oh
now i got this...

h-68-164-42-185:~ stefan$ ruby ruby.rb
ruby: No such file or directory -- ruby.rb (LoadError)
h-68-164-42-185:~ stefan$ cd documents
h-68-164-42-185:~/documents stefan$ ruby hello.rb
hello.rb:1: Invalid char `\320' in expression
hello.rb:1: Invalid char `\317' in expression
hello.rb:1: Invalid char `\021' in expression
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?
Phillip Gawlowski (Guest)
on 2007-04-18 00:46
(Received via mailing list)
smc smc 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?

Firstly:
A: Because it makes it difficult to associate responses.
Q: Why is top posting bad?

Secondly: Save your script as a text file, not as a binary.

--
Phillip "CynicalRyan" Gawlowski
http://cynicalryan.110mb.com/
http://clothred.rubyforge.org

Rule of Open-Source Programming #34:

Every successful project will eventually spawn a sub-project
Beade94a2b9a2198fd2dd40ebe64261d?d=identicon&s=25 Suraj K. (snk)
on 2007-04-18 01:14
poison tooth wrote:
> Grab a text editor and type in the following:
>
> puts "Hello World"
>
> Save the file as hello.rb and run it by typing
> ruby hello.rb"

If you just want to make sure that you can run that book example, here
is a quick low-level solution. In a terminal, run:

  echo 'puts "Hello World"' > hello.rb
  ruby hello.rb

Alternatively, you can run:

  ruby -e 'puts "Hello World"'

As for your program editing troubles, I suggest having a look at the
Ruby garden (skip down to the "Ruby development environments" section):

  http://wiki.rubygarden.org/Ruby/page/show/RubyOnMacintosh
Noah Easterly (Guest)
on 2007-04-18 01:25
(Received via mailing list)
On Apr 17, 6:28 pm, "smc smc" <fixxie.w...@gmail.com> 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 (http://en.wikipedia.org/wiki/Text_editors), 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.
smc smc (Guest)
on 2007-04-18 02:41
(Received via mailing list)
thanks
i finally got it!!!
John Joyce (Guest)
on 2007-04-18 05:06
(Received via mailing list)
while you are at it, get the book "learning unix for OS X Tiger"
You're going to need a few unix skills here. Not a lot, but it will
help you understand stuff more.
If you need more, get Unix In a Nutshell (it covers OS X, Linux, Unix)
Benjohn Barnes (Guest)
on 2007-04-18 21:43
(Received via mailing list)
On 18 Apr 2007, at 01:40, smc smc wrote:

> thanks
> i finally got it!!!

:-) Congratulations. I hope you have a lot of fun.
hemant sonker (Guest)
on 2007-04-19 08:32
(Received via mailing list)
if u r in the learning phase ,then just try scite editor.it is the best
one.
smc smc (Guest)
on 2007-04-19 10:04
(Received via mailing list)
i know quite a bit of unix so thats not a problem and i can also ask
my dad (but he dosent know ruby) :{
This topic is locked and can not be replied to.