Ruby is a scripting language. This means that Ruby programs are simply lists, or scripts, of statements to be executed. By default, these statements are executed sequentially, in the order they appear. Ruby’s control structures (described in Chapter 5) alter this default execution order and allow statements to be executed conditionally or repeatedly, for example.
Programmers who are used to traditional static compiled languages like C or Java may find this slightly
confusing. There is no special
method in Ruby from which execution begins. The Ruby interpreter
is given a script of statements to execute, and it begins executing at
the first line and continues to the last line.
(Actually, that last statement is not quite true. The Ruby
interpreter first scans the file for
and executes the code in their bodies. Then it goes back to line 1 and
starts executing sequentially. See BEGIN and END for more
Another difference between Ruby and compiled languages has to do with module, class, and method definitions. In compiled languages, these are syntactic structures that are processed by the compiler. In Ruby, they are statements like any other. When the Ruby interpreter encounters a class definition, it executes it, causing a new class to come into existence. Similarly, when the Ruby interpreter encounters a method definition, it executes it, causing a new method to be defined. Later in the program, the interpreter will probably encounter and ...