Hi,
Hello.
I am completely new to this language. I am trying to learn it on my own
by reading the book available online. I wanted to type some code and
test it while I was learning.
Welcome to Ruby.
I was wondering if someone could answer the following questions that
would help me get started on writing some small amount of code testing
it myself.
I'll sure try...
1) Just like in C++ you have a .h and a .cpp file , In this language how
would you store your file. In other words if I open emacs and want to
write a very simple small class in what format would I save this file ?
Ruby reads plain text files. It you make a test file that's full of Ruby code, you're good to go.
The traditional extension for these files is .rb, but I don't think Ruby really cares. Extensions are mainly used to support Windows and give hints to various editors/IDEs.
Unix (and Mac OS X) cares more about the "shebang" line. The first line of a Unix script is often a "sharp" (#), followed by a "bang" (!), followed by the path to Ruby. Unix uses this when the file is executed to determine what to run it with. Here's the shebang line for my Mac OS X install:
#!/usr/local/bin/ruby
A lot of people prefer:
#!/usr/bin/env ruby
That shebang can often find the right Ruby to run on differing systems.
Again, Ruby itself doesn't much care, but this is support Unix.
So, we can combine those practices to create pretty standard Ruby source that should work in most places. Here's the famous "Hello World" example, which you could save in something like "hello.rb":
#!/usr/bin/env ruby
puts "Hello world!"
__END__
2) How do you compile your code? What is the syntax?
Ruby does away with that icky "compile" step. Just run your code:
% ruby hello.rb
Better, run your code with warnings turned on, so Ruby can help you find bugs:
% ruby -w hello.rb
3) Do you need a main and a makefile ? I am sure you would need a main
to test it . If yes how do you save the main? In what format?
In Ruby, "main" is the code that appears outside methods. Just put it in your file and it will be run.
These questions may seem really stupid, but I have no idea about this
language. I have a little knowledge of C and Java, but not ruby.
Again, welcome and just shout if we can be of more help.
James Edward Gray II
···
On Feb 11, 2005, at 11:01 AM, Ghelani, Vidhi wrote: