
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 33676 Articles for Programming

1K+ Views
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 the code shown belowclass Document attr_accessor :name def initialize(name) @name = name end def set_name(name) @name = name end end d = Document.new('TP') d.set_name('TutorialsPoint') puts d.nameOutputIt will produce the following output −TutorialsPointExample 2Let's consider one ... Read More

1K+ Views
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. When you start the car by turning the key or pressing the start button, you don't necessarily need to know how the engine works or how it gets started, also what components are present in that car or what else is there. These details that are irrelevant to the driver ... Read More

253 Views
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 flow alterations in Ruby −break statementnext statementredo statementretry statementLet's consider each of these one by one.break statementWhen a condition is True in Ruby, the break statement terminates a loop.ExampleConsider the code shown below.# break statement example itr = 1 while true if itr * 6 >= 35 ... Read More

2K+ Views
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 to print any numbers that come after it. In such a case, we can use the break statement.Example 1Let's take an example and understand how the break statement works in Ruby. Consider the code shown below.# break statement in Ruby #!/usr/bin/ruby -w itr = 1 # while Loop ... Read More

1K+ Views
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 extracted from the array.SyntaxThe syntax of the slice() function is shown below −res = Array.slice(x, y)Here, x and y denote the starting index and the ending index, respectively.Example 1Now that we know a little about the slice() function on arrays, let's take a couple of examples and see how to ... Read More

732 Views
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 from that index and return all the elements before it. If the index is somehow invalid, then it returns nil.SyntaxThe syntax of the shift() function is shown below −res = Array.shift(x)Here, the argument "x" denotes the starting index.Example 1Now that we know a little about the shift() function on arrays, ... Read More

291 Views
Suppose we have an array A with m elements and another number n. Amal decided given a present for his n friend, so he will give each of them a jigsaw puzzle. The shop assistant told him that there are m puzzles in the shop, but they might differ in difficulty and size. Specifically, the ith jigsaw puzzle consists of A[i] pieces. So Amal decided that the difference between the numbers of pieces in his presents must be as small as possible. Let x be the number of pieces in the largest puzzle that he buys and y be the ... Read More

205 Views
Suppose we have an array A with n elements. A[i] represents there are A[i] number of blocks stacked on top of each other at ith column. The entire blocks are inside a closed transparent boundary box. Now if we rotate the entire big box clockwise 90°, then due to change of gravity direction, the blocks will fall, after than reverse it to its previous orientation. Then find the new array like A after these operations.Problem CategoryThis problem falls under sorting problems. Sorting is a very common problem while we are talking about different problem solving algorithms in computer science. As ... Read More

827 Views
Suppose we have an array A with n elements. Amal has decided to make some money doing business on the Internet for exactly n days. On the i-th day he makes A[i] amount of money. Amal loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence A[i]. The subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the nondecreasing order.Problem CategoryAn array in the data structure is a finite collection of elements of a specific type. Arrays are used to ... Read More

297 Views
Suppose we have two numbers n and k. We are determined to rearrange natural numbers. But there are too many natural numbers, so we have decided to start with the first n. Pick the following sequence of numbers: firstly, all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). We have to find which number will stand at the position number k.Problem CategoryVarious problems in programming can be solved through different techniques. To solve a problem, we have to devise an algorithm first, and to do that we ... Read More