Ruby is a pure object-oriented programming language. That means, everything is an object in Ruby. For example, 3 is an object of Number class. If you type
3.methods; it will return all the methods defined in the Number class.
Similarly, if you type
3.class; you will see the type of the class this object is referencing.
Every class has these two methods defined; to tell the methods defined in the class and the type of the class.
Ruby is a scripting language. Hence it has an interpreter to run the program. Ruby programs are NOT complied.
Single and Multi-line comments
Ruby supports to add comments to the source code and these are ignored by the Ruby interpreter. Comments are added by using the hash or pound (“#”) symbol. The text follows the hash symbol (“#”) considered as a comment.
Comments can be added in a new line or along with the Ruby code. Hash symbol (“#”) is used to add single line comments. But if you have multi-line comments; you can add them between the marks
=begin starts the multi-line comment and
=end ends it.
Multiple statements on a single line
Usually in Ruby we write each statement on a single line. Ruby allows to add multiple statements on a single line; but each statement should be separated by a semicolon (“;”). If you are writing a single statement per line, it is optional to add a semicolon (“;”) at the end of each statement. But, if you add multiple statements on a single line; it is mandatory to separate each statement by a semicolon (“;”).
You can use strings either in single quotes (” ‘ “) or in double quotes (‘ ” ‘).
| Nick |