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
- Define methods with default and keyword arguments
- Pass a block to a method and call it with yield
- Transform collections using map, select and reduce
- Explain the difference between a proc and a lambda
- Return multiple values from a method using an array
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.