Category: 01. Ruby

  • Methods

    Ruby methods are very similar to functions in any other programming language. Ruby methods are used to bundle one or more repeatable statements into a single unit. Method names should begin with a lowercase letter. If you begin a method name with an uppercase letter, Ruby might think that it is a constant and hence…

  • Loops

    Loops in Ruby are used to execute the same block of code a specified number of times. This chapter details all the loop statements supported by Ruby. Ruby while Statement Syntax Executes code while conditional is true. A while loop’s conditional is separated from code by the reserved word do, a newline, backslash \, or a semicolon ;. Example This will produce the following result…

  • if…else, case, unless

    Ruby offers conditional structures that are pretty common to modern languages. Here, we will explain all the conditional statements and modifiers available in Ruby. Ruby if…else Statement Syntax end if expressions are used for conditional execution. The values false and nil are false, and everything else are true. Notice Ruby uses elsif, not else if nor elif. Executes code if the conditional is true.…

  • Operators

    Ruby supports a rich set of operators, as you’d expect from a modern language. Most operators are actually method calls. For example, a + b is interpreted as a.+(b), where the + method in the object referred to by variable a is called with b as its argument. For each operator (+ – * / % ** & |…

  • Variables, Constants and Literals

    Variables are the memory locations, which hold any data to be used by any program. There are five types of variables supported by Ruby. You already have gone through a small description of these variables in the previous chapter as well. These five types of variables are explained in this chapter. Ruby Global Variables Global…

  • Classes and Objects

    Ruby is a perfect Object Oriented Programming Language. The features of the object-oriented programming language include − These features have been discussed in the chapter Object Oriented Ruby. An object-oriented program involves classes and objects. A class is the blueprint from which individual objects are created. In object-oriented terms, we say that your bicycle is an instance of…

  • Syntax

    Let us write a simple program in ruby. All ruby files will have extension .rb. So, put the following source code in a test.rb file. Here, we assumed that you have Ruby interpreter available in /usr/bin directory. Now, try to run this program as follows − This will produce the following result − You have seen…

  • Environment Setup

    Local Environment Setup If you are still willing to set up your environment for Ruby programming language, then let’s proceed. This tutorial will teach you all the important topics related to environment setup. We would recommend you to go through the following topics first and then proceed further − Popular Ruby Editors To write your…

  • Overview

    Ruby is a pure object-oriented programming language. It was created in 1993 by Yukihiro Matsumoto of Japan. You can find the name Yukihiro Matsumoto on the Ruby mailing list at www.ruby-lang.org. Matsumoto is also known as Matz in the Ruby community. Ruby is “A Programmer’s Best Friend”. Ruby has features that are similar to those of…