March 23 - Pass Multiple Blocks to a Method by Leveraging Lambdas in Ruby
In many cases, lambdas are the most effective when they're used in conjunction with methods. A method is limited to taking a single block in Ruby, however by leveraging lambdas you are able to pass in as many blocks as needed.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
  • Complete the Exercise
Video locked
This video is viewable to users with a Bottega Bootcamp license

Summary

Implement a method that can accept multiple blocks by leveraging lambdas.

Exercise Description

Build a method that takes multiple lambdas as arguments in order to illustrate how a single method can be passed multiple blocks as arguments.

Real World Usage

By default, a method in Ruby is limited to only receiving a single block as an argument. This is where lambdas (also known as closures in other languages) are able to extend the functionality of a single method. A method can take an unlimited number of lambdas as argument, so therefore lambdas allow you to give plain Ruby methods the ability to accept multiple blocks as arguments. This exercise helps to showcase this behavior by building a User tracking solution.

Test Cases

Code File