Skip to content

Latest commit

 

History

History
33 lines (21 loc) · 1008 Bytes

readme.md

File metadata and controls

33 lines (21 loc) · 1008 Bytes

About Blocks

Introduction

Blocks, procs and lambdas (also known as closures in other languages) are one of the most powerful constructs in Ruby. There are a variety of different ways to create and use blocks, which this workshop aims to clarify.

Walk-through

Coding walk-through to be done in person with group.

Solutions

Notes

  • Procs are objects, blocks are not
  • Blocks are part of the syntax of a method call
  • Both proc and lambda return Proc objects
  • Lambdas assert arity (number of passed arguments)
  • Return inside a lamba returns flow to the outer code scope
  • Return inside a proc is executed in the outer scope (as if inside that scope directly)