Mukul Latiyan has Published 322 Answers

Types of iterators in Ruby

Mukul Latiyan

Mukul Latiyan

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

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

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

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

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

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

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

Transpose() function in Ruby Programming

Mukul Latiyan

Mukul Latiyan

Updated on 25-Jan-2022 11:12:23

The transpose function in Ruby is mainly used to return the transpose of an array or a matrix.Syntaxarray.transposeOrMatrix.transposeLet's take a couple of examples of the transpose function on array first and then on matrices.Example 1Consider the code shown below# transpose() in array # array declaration first_arr = [[18, 22], [33, ... Read More

Array push(), pop() and clear() functions in Ruby

Mukul Latiyan

Mukul Latiyan

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

The most widely used functions in Ruby when it comes to arrays are push(), pop(), and clear() functions. These functions are used when we want to enter, take out and clear the array data, respectively. In this article, we will learn about all these functions one by one.push() FunctionThe push ... Read More

String reverse vs reverse! function in Ruby

Mukul Latiyan

Mukul Latiyan

Updated on 25-Jan-2022 11:02:01

In Ruby, we have two functions available to us in case we want to reverse the contents of a string. These two functions are reverse and reverse!. While both of them are used to reverse the string, the only difference between them is that the reverse function reverses the string ... Read More

How to push and pop elements in a queue in Ruby?

Mukul Latiyan

Mukul Latiyan

Updated on 25-Jan-2022 10:55:33

In this article, we will learn how to push (insert) and pop (remove) elements in a queue in Ruby.In Ruby, we can insert elements into a queue with the help of the push function. The syntax of the push function is shown below.queueName.push(element)Notice that the above syntax accepts one argument, ... Read More

Previous 1 ... 3 4 5 6 7 8 9 ... 33 Next
Advertisements