Web Development with Ruby: An Introduction to Ruby on Rails Ruby on Rails is a popular web development framework for creating dynamic websites and web applications. It is an open-source technology that is based on the…
Introduction to Ruby on Rails: Building Web Applications Quickly Ruby on Rails is a powerful web application framework that is designed to make web development simple, fast and efficient. It is based on the popular…
Lazy evaluation is an evaluation strategy that delays the assessment of an expression until its value is needed. Ruby introduced a lazy enumeration feature. Lazy evaluation increases performance by avoiding needless…
In our previous challenge, we explored one way to pass a variable number of arguments to our methods. While it may seem handy feature to have, except few circumstances, you are never going to use that many variables for…
In the previous challenge, we learned to use methods to abstract similar computations into logical chunks of code that otherwise would be difficult to manage. Methods, in a way, behave like a black box. The programmer…
Another function often used with data collections is one which groups the elements according to some evaluation result. Consider the following example. Let's say you have a list of 100 integers and you want to group…
Ruby offers various enumerables on collections that check for validity of the objects within it. Consider the following example:> arr = [1, 2, 3, 4, 5, 6]=> [1, 2, 3, 4, 5, 6]> h = {"a" => 1, "b" => 2, "c" => 3}=> {"a"…
A common scenario that arises when using a collection of any sort, is to get perform a single type of operation with all the elements and collect the result. For example, a sum(array) function might wish to add all the…
Beside simple methods to iterate over objects, Ruby Enumerable provides a number of important higher order constructs that we shall explore in further challenges. One of such important methods is collect method, also…
In the previous challenge, we learned about each method being central to all of the methods provided by Enumerable class. One of such useful methods is each_with_index which allows you to iterate over items along with…
In control structures tutorial, we learned about various methods to iterate over a collection like unless, loop and the most commonly used eachmethod. Ruby, however, provides an Enumerable module which packages a bunch…
In this tutorial, we'll learn about the methods in String class that help us to search and replace portions of the string based on a text or pattern. String.include?(string) - Returns true if str contains the given…
Text info can be read from varied sources and is often unsuitable for direct processing or usage by core functions. This necessitates methods for post-processing and data-fixing. In this tutorial, we'll learn how to…
In our encoding tutorial, we learned about the different ways Ruby 1.8 and Ruby 1.9 (and higher versions) represent strings internally. The major difference is a wide range of encoding (non-ascii) support in the later…
When you index a string, you extract or alter the portions. This is perhaps the most important operation you want to perform on strings. The string class provides a convenient array-like square bracket [] operator…
In Ruby, strings are objects of the String class, which defines a powerful set of operations and methods for manipulating text (e.g., indexing, searching, modifying, etc.). Here are a few easy ways to create…
Numbers, boolean values and strings are some of the fundamental data types that we have explored in our previous challenges. In this set of tutorials, we turn our attention to the data type referred to as String or…
Currying is a technique in which a function accepts parameters and turns it into a sequence of functions, each of them take 1 parameter. Example :- In the above example, lambda take two parameters , and return the…
In Partial Application, we create a lambda that takes a parameter and returns a lambda that does something with it. Example: In the above example, the lambda will take number as a parameter, and return a lambda. When…
Closure is a function/method that: ► Can be passed around like an object. It can be treated like a variable, which can be assigned to another variable, passed as an argument to a method. ► Remembers the value of…