Author: admin

  • Ruby Hashes

    A Ruby hash is a collection of unique keys and their values. They are similar to arrays but array use integer as an index and hash use any object type. They are also called associative arrays, dictionaries or maps. If a hash is accessed with a key that does not exist, the method will return…

  • Ruby Strings

    Ruby string object holds and manipulates an arbitary sequence of bytes, typically representing characters. They are created using String::new or as literals. Quotes Ruby string literals are enclosed within single and double quotes. Example: Output: Accessing string elements You can access Ruby string elements in different parts with the help of square brackets []. Within square brackets…

  • Ruby Modules

    Ruby module is a collection of methods and constants. A module method may be instance method or module method. Instance methods are methods in a class when module is included. Module methods may be called without creating an encapsulating object while instance methods may not. They are similar to classes as they hold a collection…

  • Ruby Blocks

    Ruby code blocks are called closures in other programming languages. It consist of a group of codes which is always enclosed with braces or written between do..end. The braces syntax always have the higher precedence over the do..end syntax. Braces have high precedence and do has low precedence. A block is written in two ways, Both are…

  • Ruby Methods

    Ruby methods prevent us from writing the same code in a program again and again. It is a set of expression that returns a value. Ruby methods are similar to the functions in other lnguages. They unite one or more repeatable statements into one single bundle. Defining Method To use a method, we need to…

  • Ruby Class and Object

    Here, we will learn about Ruby objects and classes. In object-oriented programming language, we design programs using objects and classes. Object is a physical as well as logical entity whereas class is a logical entity only. Ruby Object Object is the default root of all Ruby objects. Ruby objects inherit from BasicObject (it is the parent class…

  • Ruby Comments

    Ruby comments are non executable lines in a program. These lines are ignored by the interpreter hence they don’t execute while execution of a program. They are written by a programmer to explain their code so that others who look at the code will understand it in a better way. Types of Ruby comments: Ruby…

  • Ruby redo Statement

    Ruby redo statement is used to repeat the current iteration of the loop. The redo statement is executed without evaluating the loop’s condition. The redo statement is used inside a loop. Syntax: Example: Output: Ruby retry Statement Ruby retry statement is used to repeat the whole loop iteration from the start. The retry statement is…

  • Ruby Break Statement

    The Ruby break statement is used to terminate a loop. It is mostly used in while loop where value is printed till the condition is true, then break statement terminates the loop. The break statement is called from inside the loop. Syntax: Example: Output: Ruby Next Statement The Ruby next statement is used to skip…

  • Ruby Until Loop

    The Ruby until loop runs until the given condition evaluates to true. It exits the loop when condition becomes true. It is just opposite of the while loop which runs until the given condition evaluates to false. The until loop allows you to write code which is more readable and logical. Syntax: Example: Output: