. View this ad or post your own Ruby Job!

Monday, October 24, 2005

Ways To Run Ruby

What have I found out so far? Having come from a Java background, I thought these series of slides - 10 Things Every Java Programmer Should Know About Ruby, would be useful. I went through them but did not follow much, for now. I shall come back to this later.

So how do I get started with Ruby? An online version of the first edition of Programming Ruby - The Pragmatic Programmer's Guide is available. The second edition needs to be purchased (18th Nov. - Marsee Henon from O'Reilly has sent me a review copy of this book. Thank you Marsee.). I also realised that the first edition book is available in the Ruby software that I had installed earlier.

I opened the Programming Ruby - The Pragmatic Programmer's Guide. While going through this book, I came across this - "there are two ways to run Ruby - interactively and as a program."

When you installed your Ruby software, the System Environment Variable path is already set to point to the bin folder of Ruby. Interactive Ruby means using a DOS window. To do this open a new DOS window and type irb --simple-prompt A prompt appears as >> I can start using this as a simple calculator. If I type 3+4 and then press the enter key, I get 7. Numbers can be Integers or Floating-point numbers.I found out that the simple operators like + - * / ** % are available in Ruby. Typing exit or quit, closes the DOS window. You can also customize this shell.

Before getting into the syntax of the language, let us look at the other option ie. running a Ruby program. Also, it would be a good idea to create a folder somewhere to keep all of your programs. Make sure that when you save a program, you save it into this folder.
Now type the following in your text editor -
puts "Hello World"
Save the file as hello.rb in your Ruby source code folder. Open a DOS window and go to your Ruby source code folder. Then run the program by typing:
ruby hello.rb
Note: puts simply writes onto the screen whatever comes after it. puts really means put string.

Ruby is the interpreted language, so you don't have to recompile to execute the program written in Ruby.

That's it for now.

First Post | Previous | Next

Technorati Tags:
Blogs linking to this article


Post a Comment

Links to this post:

Create a Link

<< Home

Valid XHTML 1.0!