Ruby Programming: An Introduction

Ruby is a popular open source, cross-platform, object-oriented, dynamic, scripting, interpreted programming language. It was invented in the year 1993 by Yukihiro Matsumoto (Matz). Ruby is cross-platform, that means if we develop a Ruby program based on one machine; it’s likely to run the same program without any changes on different machines.

In order to develop or run Ruby programs, first step is we need to install Ruby on the system.

Lets write a simple example Ruby program to display “Hello, World!” message on the screen.

# sample.rb

puts 'Hello, World!'

That’s it. Are you so surprised?. Aabove code is a simple Ruby program which will display “Hello, World!” text on the screen. In above code, we have used Ruby‘s puts function; which is used to display the given text on the screen.

Lets run our application. Type the below command at command prompt:

ruby sample.rb

It will display “Hello, World!” message on the screen. That’s it! We have successfully created our first Ruby program.

Actually whenever we run the Ruby program; first, Ruby will tokenize the code; next, parse these tokens and finally, interprets the statements into low-level instructions that Ruby can execute.

Have you observed some thing here? Above statement will not generate any files. Usually if we compile or interpret the program, the compiler or interpreter will generate additional output files. For eg: While compiling Java program “javac” generates a “.class” file. But Ruby will handle all these internally and generates the output without generating any additional files. Hence we will not see any additional files when we run the above command from command prompt.

We can use Ruby to develop small applications to enterprise level applications. Usually most programmers (who likes Ruby) will use “Ruby on Rails” to develop Web applications. “Ruby on Rails” is an open source framework built using Ruby; which makes the development of Web applications simple.

Now we know how to run Ruby programs. Lets discuss about more on Ruby programming topics in our future articles.

🙂 Sahida

Leave a Reply