Mukul Latiyan has Published 474 Articles

Lambda Functions in Ruby

Mukul Latiyan

Mukul Latiyan

Updated on 25-Jan-2022 11:52:10

326 Views

In Ruby, we can take the help of lambda functions when we want to use anonymous functions. They are also treated like objects in Ruby, as everything in Ruby is treated as objects.SyntaxThe syntax of declaring a lambda function is shown below.lambda = lambda {}Or, we can also make use ... Read More

Comparable module in Ruby

Mukul Latiyan

Mukul Latiyan

Updated on 25-Jan-2022 11:49:27

348 Views

In Ruby, the class whose objects can be ordered uses the Comparable mixin. Class definitions need to include an operator to compare receivers with each other. The operator will return either -1, 0, or 1.It returns -1 if the receiver is less than another object.If it is greater than another ... Read More

Array reverse() vs reverse! in Ruby

Mukul Latiyan

Mukul Latiyan

Updated on 25-Jan-2022 11:46:03

740 Views

In this article, we will explore the two most widely used methods on arrays in Ruby. These are the reverse() method and the reverse! method.reverse() methodThe reverse() method in Ruby reverses the content of the array and returns a new array. Now, let's take a couple of examples to understand ... Read More

How does Inheritance work in Ruby?

Mukul Latiyan

Mukul Latiyan

Updated on 25-Jan-2022 11:42:32

1K+ Views

Inheritance is a key aspect of any OOP language. With the help of inheritance, we can reuse the methods that are defined on the parent class (also known as superclass) in the child class (also known as subclass).In Ruby, single class inheritance is supported, which means that one class can ... Read More

Types of iterators in Ruby

Mukul Latiyan

Mukul Latiyan

Updated on 25-Jan-2022 11:38:00

120 Views

In Ruby, we have multiple types of iterators available to us. We will learn about the most common ones in this article, one by one.Each IteratorUsing this iterator, you can iterate over an array or a hash, returning each element as it is returned.Example 1Consider the code shown below# each ... Read More

Thread life cycle and its states in Ruby

Mukul Latiyan

Mukul Latiyan

Updated on 25-Jan-2022 11:35:06

431 Views

In Ruby, we can create threads which have different states and a life cycle which denotes its time since it started till its ending. In this article, we will take a look at the life cycle of a thread in Ruby.Thread Life Cycle in RubyThe Thread life cycle is a ... Read More

How to freeze objects in Ruby?

Mukul Latiyan

Mukul Latiyan

Updated on 25-Jan-2022 11:31:28

302 Views

Sometimes a situation arises where we would want to freeze the object instance so that it cannot be instantiated or modified and in Ruby, we can do that with the help of the freeze keyword.The approach is to invoke the Object#freeze statement.When we freeze an object, we are basically turning ... Read More

Range class methods in Ruby

Mukul Latiyan

Mukul Latiyan

Updated on 25-Jan-2022 11:21:14

210 Views

Range is a class in Ruby. Ruby ranges represent a set of values that have a beginning and an end. A range can be represented as a number, character, string, or object. A range is constructed with start_point...end_point, start_point...endpoint literals, or with ::new. It provides flexibility and reduces the size ... Read More

Unless statement and Unless modifier in Ruby

Mukul Latiyan

Mukul Latiyan

Updated on 25-Jan-2022 11:18:14

2K+ Views

Unless StatementWe know that we can use the if statement when we want to run some code based on a condition that evaluates to True. Ruby also provides a special statement known as unless statement that can be used to run some code based on the condition that evaluates to ... Read More

How to use BigDecimal in Ruby?

Mukul Latiyan

Mukul Latiyan

Updated on 25-Jan-2022 11:15:52

963 Views

Using BigDecimal, you can perform floating point decimal arithmetic with arbitrary precision. Let's try to understand the BigDecimal usecase with the help of an example. We will take two examples, where the first one will make use of no BigDecimal and in the second example, we will use BigDecimal.Consider the ... Read More

Advertisements