Mukul Latiyan has Published 322 Answers

How Does Encapsulation Work in Ruby?

Mukul Latiyan

Mukul Latiyan

Updated on 12-Apr-2022 07:53:34

Encapsulation is the ability to wrap the data into a single unit. In simple terms, it's a mechanism to wrap data and the code that manipulates the data. In Ruby, we can achieve encapsulation with the help of classes.Let's consider a very simple example where we will implement encapsulation.Example 1Consider ... Read More

How to implement Data Abstraction in Ruby?

Mukul Latiyan

Mukul Latiyan

Updated on 12-Apr-2022 07:48:08

Abstraction is an object-oriented programming concept, where the essential attributes of something are shown and all the unnecessary ones are hidden. With this approach, one can hide the implementation details and provide only the important interface.A very good example of abstraction is your car. It's a great example of abstraction. ... Read More

Control flow alterations in Ruby

Mukul Latiyan

Mukul Latiyan

Updated on 12-Apr-2022 07:43:48

In addition to loops, conditionals, and iterators, Ruby has some statements that are used to change the control flow in a program. In other words, these statements are pieces of code that execute one after the other until a condition is met.In this article, we will explore the following control ... Read More

How to use the 'break' and 'next' statements in Ruby?

Mukul Latiyan

Mukul Latiyan

Updated on 12-Apr-2022 07:19:38

break Statement in RubyIn Ruby, we use the break statement in order to make sure that we exit a certain loop after a condition. For example, suppose we want to print the numbers from 1 to 10, but once we hit the number 5, we just don't want the loop ... Read More

Array slice function in Ruby

Mukul Latiyan

Mukul Latiyan

Updated on 12-Apr-2022 07:14:56

Sometimes we may want to exact a portion from an array data and perform some operation on it. In Ruby, we can do that with the help of the slice() function that takes two arguments, both of them indices, that are used to define a subsequence which then can be ... Read More

Array shift function in Ruby

Mukul Latiyan

Mukul Latiyan

Updated on 12-Apr-2022 07:12:40

Sometimes we need to extract a portion of an array data and perform some operation on the extracted data. In Ruby, we can perform such operations with the help of the shift() function.The shift() function takes one argument, which is an index that is used to remove the first element ... Read More

How to handle errors within WaitGroups in Golang?

Mukul Latiyan

Mukul Latiyan

Updated on 22-Feb-2022 06:58:49

There are chances that we might get some panic while running multiple goroutines. To deal with such a scenario, we can use a combination of channel and waitgroups to handle the error successfully and not to exit the process.Let's suppose there's a function that when invoked returns a panic, which ... Read More

How to check if a file exists in Golang?

Mukul Latiyan

Mukul Latiyan

Updated on 22-Feb-2022 05:56:16

In order to check if a particular file exists inside a given directory in Golang, we can use the Stat() and the isNotExists() function that the os package of Go's standard library provides us with.The Stat() function is used to return the file info structure describing the file. Let's first ... Read More

How to wait for a goroutine to finish in Golang?

Mukul Latiyan

Mukul Latiyan

Updated on 22-Feb-2022 05:46:39

We know that goroutines can be a bit tricky at first, and often we find cases where the main goroutines will exit without giving a chance to the inside goroutines to execute.In order to be able to run the goroutines until the finish, we can either make use of a ... Read More

How to concatenate two slices in Golang?

Mukul Latiyan

Mukul Latiyan

Updated on 22-Feb-2022 05:43:33

Whenever we talk about appending elements to a slice, we know that we need to use the append() function that takes a slice as the first argument and the values that we want to append as the next argument.The syntax looks something like this.sl = append(sl, 1)Instead of appending a ... Read More

Advertisements