ruby-blocks-procs-lambdas

Explain Ruby blocks, procs, and lambdas for functional programming patterns.

187|20|Updated Nov 20, 2025
One-click install
npx skills add https://github.com/TheBushidoCollective/han --skill ruby-blocks-procs-lambdas
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ruby-blocks-procs-lambdas
Source: https://github.com/TheBushidoCollective/han/tree/main/jutsu/jutsu-ruby/skills/ruby-blocks-procs-lambdas
Command: npx skills add https://github.com/TheBushidoCollective/han --skill ruby-blocks-procs-lambdas

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill teaches Ruby's blocks, procs, and lambdas to express control flow with higher-order functions and closures.

Core Features & Use Cases

  • Blocks & yields: Define and pass blocks to methods.
  • Procs & lambdas: Understand differences in behavior, arity, and return semantics.
  • Closures: Create functions that capture surrounding variables.

Quick Start

Write a small method that yields to a block and compare it with a Proc and a lambda.

Frequently Asked Questions about ruby-blocks-procs-lambdas

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What's the difference between blocks, procs, and lambdas in Ruby?

Blocks, procs, and lambdas are all closures in Ruby, but they differ in syntax, arity checking, and return behavior. Blocks use do...end or {...}, procs created with Proc.new are lenient with arguments, and lambdas enforce strict arity and return to their enclosing method rather than the caller.

How do I use yield to pass a block to a Ruby method?

Define a method with a block parameter using yield to invoke it. When you call the method, pass a block with do...end or {...} syntax; yield executes that block within the method's context, enabling callbacks and iteration patterns.

When should I use a lambda instead of a Proc?

Use lambdas when you need strict argument validation and predictable return behavior; they enforce arity and return only from the lambda itself. Use Procs for flexible callbacks where lenient argument handling and early returns to the enclosing method are acceptable.

How do closures work in Ruby blocks and lambdas?

Blocks and lambdas capture variables from their enclosing scope, creating closures that retain access to those variables even after the defining scope ends. This enables stateful callbacks, partial application, and higher-order functions.

What is symbol-to-proc conversion and how do I use it?

Symbol-to-proc converts a symbol to a proc using &:method_name syntax in method calls like map(&:upcase). This creates a closure that applies the method to each element, reducing boilerplate when passing simple method calls as blocks.

Can I use currying and partial application with Ruby procs?

Yes, both lambdas and Procs support currying through the curry method, which returns a proc that accumulates arguments and fires when arity is satisfied. Partial application locks in some arguments, creating specialized functions for reuse.