Skip to main content

Methods for Rubys

Ruby methods are named blocks of code defined with def, and blocks are chunks of code passed to a method, often between do and end or braces. Together they power Ruby's iteration style, where methods like each, map and select take a block and yield values to it, and procs and lambdas store code as objects.

Stage: Basics · Part of the Ruby roadmap · Last reviewed 19 November 2026

What to learn in Methods

Methods interview questions

How does yield work in a Ruby method?

yield runs the block that was passed to the method, optionally giving it arguments. If the method is called without a block, yield raises an error, so code often checks block_given? first. This is how each and map are written in Ruby.

What is the difference between a proc and a lambda?

A lambda checks its argument count strictly and return exits only the lambda. A proc is lenient about arguments, and return inside a proc returns from the surrounding method. Lambdas behave like methods, which makes them safer for most uses.

Where Methods fits in the Ruby roadmap

Methods belongs to the Basics stage (beginner level), which takes about 17 hours. Syntax and flow.

Back to the full Ruby roadmap