Ruby Overview


Ruby is a pure object oriented programming language. It was conceived on February, 1993 as a balanced functional / imperative programming language by Yukihiro "Matz" Matsumoto. "I wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. That's why I decided to design my own language".

Ruby supports multiple programming paradigms, including functional, object oriented, imperative and reflective. It also has a dynamic type system and automatic memory management. Combining syntax inspired by Perl with Smalltalk-like features, it is therefore similar in varying respects to Python, Eiffel, Ada, Lisp, Dylan, and CLU.

Following are the key turning points in Ruby history,

You can find the name Yukihiro Matsumoto on the Ruby mailing list at Ruby Forum

Ruby is "A Programmer's Best Friend".

Ruby Language Features:

How Ruby works?


Ruby is designed around Objects and the common cases of working with them:

      class TalkToMe
        def say
          puts "Hello world!"
        end
      end
       
      TalkToMe.new.say #=> "Hello world!"
       
      # Much better then doing this:
      TalkToMe.new().say()
      

Ruby has a wonderful command-line tool called irb (Interactive Ruby). Written by Keiju Ishitsuka, it comes along with Ruby installation out of the box.

You type Ruby commands and expressions, and irb executes them on the spot.

Within the IRb shell, you can immediately view expression results, line by line.

Just type irb at your command prompt and an Interactive Ruby Session will start as given below:

      C:\>irb -v
      irb 0.9.5(05/04/13)
      
      C:\>irb
      irb(main):001:0> def hello
      irb(main):002:1> out = "Hello World"
      irb(main):003:1> puts out
      irb(main):004:1> end
      => nil
      irb(main):005:0> hello
      Hello World
      => nil
      irb(main):006:0> exit
      
      C:\>
      

A lot of what you'll see and write in Ruby programs are method calls. Method calls sometimes consist simply of the name of a method, in bareword form, possibly followed by one or more arguments to the method.

It's highly recommended that you create a separate directory for examples you copy from here. Something like this should be suitable:

      C:\>cd
      C:\>mkdir ruby4rails
      C:\>cd ruby4rails
      

Type the code using any text editor (SciTE, vi, Emacs, Notepad, and so on), and save it under a filename like this: myprogram.rb in your ruby4rails directory.

Notice: Word Processors are useless into this. You really need a Plain Text Editor.

You now have a Ruby program on your disk, and you can run it with the following:

      C:\>ruby myprogram.rb