2. Introduction:
1. An Imperative language
2. Object – oriented language
3. Can be used on all platforms
4. Programmer friendly
3. ▶ Easy syntaxes :
Loops do not need blocks.
Pre-defined blocks for loops and conditions.
Accessing of elements is easy.
No need to specify the data types of variables.
Key words are easier to use that follow basic English language.
4. ▶ Variables can be easily classified into various types.
▶ Single statement without any class or method can also be
executed.
▶ Many predefined methods for arithmetic operations.
5. ▶ Ruby considers every entity in it as an object.
▶ Object creation is very easy and it can access every variable and
method in the class and also super class.
6. Classes in Ruby:
▶ Classes can be used in Ruby with methods and variables in it.
▶ Classes may contain Class, Global, Instance , Block variables.
▶ Object must be created to access a class created. The object of a
class or any variable can also be created.
▶ Ruby supports Single Inheritance from parent class.
Inheritance uses “<“ symbol to access super class
elements.
7. Variables and Methods :
▶ Ruby has five types of variables :
▶ Global : These can be accessed along all the classes and the
objects in the package or project. It is classified by “ $“
▶ Instance : These can be accessed in the class in which it is declared
. It is classified by “ @“
▶ Class variables : These can be accessed in the class in which it is
declared . It should be compulsory initialised before it is used in the
further operations .It is classified by “ @@“
▶ Block variables: These can be accessed only in the Block in which it
is declared . The scope of the variables is only within the block.
▶ Ruby Pseudo-Variables: these are constants like ‘true’ ,’ false’, ‘self’ ,
‘nil’ .
8. Ranges :
▶ Ruby has a special feature named Ranges.
▶ It is same as the ‘for’ loop in various programming languages .
▶ This iterates the continuous variables in the range.
▶ Example:
▶ (1..10) gives values from 1 to 10 .
▶ (‘a’..’g’) gives characters from a to g in alphabetical order.