Mukul Latiyan has Published 322 Answers

Number Parsing in Golang

Mukul Latiyan

Mukul Latiyan

Updated on 21-Feb-2022 07:14:30

Number parsing in Go is about converting the numbers that are present in string form to number form. By number form, we mean that these numbers can either be converted into integers, floats, etc.The most widely used package for number parsing is the "strconv" package that Go library provides us ... Read More

How to measure the execution time in Golang?

Mukul Latiyan

Mukul Latiyan

Updated on 21-Feb-2022 07:07:32

In Go, we have a package named time that is present in Go's standard library. This time package contains different useful functions that we can use to calculate the time taken by a code block or even a function in Go.The most widely used functions are time.Sleep(), time.Since() and time.Now(). ... Read More

How to use closures in Golang?

Mukul Latiyan

Mukul Latiyan

Updated on 21-Feb-2022 07:01:45

In order to understand what closures are, we must know what anonymous functions are and how we can use them.Anonymous functionsIn Go, anonymous functions are those functions that don't have any name. Simply put, anonymous functions don't use any variables as a name when they are declared.We know that we ... Read More

How to use functions from another package in Golang?

Mukul Latiyan

Mukul Latiyan

Updated on 21-Feb-2022 06:46:20

We know that every code in Golang is present inside a package, which can either be an executable one or a utility one. The executable package name is usually main and the name of the utility package can be anything, in most cases, it is the name of the folder.Suppose ... Read More

How to read a file into a string in Golang?

Mukul Latiyan

Mukul Latiyan

Updated on 21-Feb-2022 06:24:17

To read a file into a string, we need to make use of the io/ioutil package that Go's standard library provides us with.Inside the io/ioutil package, there's a function called ReadFile() which is used to open a file and then convert its contents into a slice of bytes, and if ... Read More

How to parse JSON files in Golang?

Mukul Latiyan

Mukul Latiyan

Updated on 21-Feb-2022 06:19:53

Suppose we want to read a JSON file in Go. By reading, we mean that we want to convert the file data into a struct in Go.Consider the JSON file shown below that we will use to read and then convert the data into the structure.{    "users": [   ... Read More

Lambda Functions in Ruby

Mukul Latiyan

Mukul Latiyan

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

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

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

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

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

Advertisements