Author: Saim Khalid
-
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 if conditional [then] code… code…]… 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…
-
Comments
Comments are lines of annotation within Ruby code that are ignored at runtime. A single line comment starts with # character and they extend from # to the end of the line as follows − #!/usr/bin/ruby -w# This is a single line comment. puts “Hello, Ruby!” When executed, the above program produces the following result…
-
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
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. #!/usr/bin/ruby -w puts “Hello, Ruby!”; Here, we assumed that you have Ruby interpreter available in /usr/bin directory. Now, try to run this program as follows − $ ruby test.rb This will…
-
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…
-
Ruby Tutorial
What is Ruby? Ruby is an open-source and high-level programming language, which is known for its simplicity and developer-friendliness. This is designed by Yukihiro Matsumoto with the purpose of making programming more enjoyable and productive for developers. Ruby includes a lot of key features like its Object-Oriented, Dynamic Typing, Readable Syntax, and a large Standard…
-
Loan EMI Calculator
Calculate monthly EMI for a loan.COMPUTE, ACCEPT, DISPLAY. Formula: EMI=P×R×(1+R)N(1+R)N−1EMI = \frac{P \times R \times (1+R)^N}{(1+R)^N – 1}EMI=(1+R)N−1P×R×(1+R)N Where: