Coding Exercises

Demonstrate Ruby Procs / Lambdas vs Methods for Variable Scope

There are some key differences between procs / lambdas and traditional methods in Ruby, however the differences can many times be subtle. In this exercise we’ll examine how variable scope is processed differently between the different options.


Build a program that illustrates the differences in variable scope in Ruby between Procs / Lambdas, and traditional methods.

Exercise File

Code File

Exercise Description

Build a traditional method and a lambda or Proc and illustrate how the two processes have different access levels for local variables.

Real World Usage

This exercise showcases one of the subtle differences between Procs / lambdas and plain Ruby methods. At a high level it may seem like the three options can be used interchangeably, however in this guide we’ll walk through how they approach variable access much differently.


Can be found on the solutions branch on github.

Jordan Hudgens
the authorJordan Hudgens


  • Hi, Jordan.
    Very helpful tutorial. Clear things out really.

    By the way, I was very curious about the way editor(vim?) just commented each return value in an instant with the file execution(or something else?). What tool are you using here? Vim plugin?

Leave a Reply