Archive for the 'Syntax' Category

First Steps through Ruby on Rails


Image Source:www.flickr.com

Classes, attributes, methods, and objects are the core of any Object-Oriented language. I am going to discuss how these classes, attributes, methods etc can be implemented in Ruby. There are two types of classes ‘close-ended’ and ‘open-ended’. If a class is close-ended, then new functionalities cannot be added to it without inheriting the class.
If a class is open-ended, then new functionalities can be added to it without inheriting it. Ruby is open-ended.
The class declared and defined just now is an empty class as it doesn’t contain any attributes or methods. You will notice that the procedure to define methods in ruby is very simple. def is the keyword used to define methods.
In ruby we don`t use brackets to define a set of code and we don`t use any semicolon at the end of the statements.

Syntax of Ruby Programming Part 1

According to Ruby Programming experts, The syntax of Ruby is somewhat similar to Perl and Python because the class and method definitions are signaled by keywords. The variables of Ruby and Perl vary because the variables are not prefixed with a sigil. It changes the semantics of scope when the variable is used. The obvious difference of C and Perl is the keywords. It is usually used to define logical code blocks without the braces. The Line breaks are significant and are taken as the end of statement. It is equivalent to semicolon (;). In contrast to Python, the indication is of no significance.

Syntax of Ruby Programming Part 2

The difference of Ruby from Python and Perl is the ability to keep all of its instance variables completely private to the class and it can only be exposed by the accessor methods. In Ruby Language, the accessor methods can be written with a single line of code. The use of parentheses is not required. In Python, once a programmer uses publicly exposed instance variable, the implementation can later be to used as a private instance variable exposed through a property descriptor. Ruby programming actually removes this design decision by forcing all instance variables to be private. In a way, Ruby also provides a simple way to declare set and get methods.