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…
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…
Lambdas are anonymous functions. Lambdas in Ruby are objects of the class Proc. They are useful in most of the situations where you would use a proc. The simplest lambda takes no argument and returns nothing as shown…
Passing blocks is one way to pass functions as arguments to other functions. Blocks are one of the very few exceptions to the "everything is an object" rule in Ruby. Blocks are not objects, and they can't be saved to…
Higher order functions are one of the key components of functional programming. A higher order function is a tool that takes other functions as parameters or returns them as a result. Blocks are nameless methods that…
In our previous challenges, we explored some ways to pass arguments to our methods; however, they were limited in terms of the number of arguments we can pass to them. Using default parameters allows us to lower the…
In our previous challenges, we have been using methods (def method() .. endconstruct) to abstract compound operations, perform data manipulations and learn various concepts of the language, without talking in much…