Blocks
Last updated
What is Blocks?
Blocks are chunks of code that can be passed to methods as if they were arguments. They are defined using either do...end or curly braces {}. Blocks are not objects themselves, but they can be converted into objects called Procs. Methods can then execute the code within the block using the yield keyword. Blocks are a fundamental part of Ruby's expressiveness, allowing for powerful iteration and control flow patterns.
Free resources to learn Blocks
More in stage 18: Metaprogramming
Blocks: common questions
Can I learn Blocks in Hindi?
This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain Blocks in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.
Is this Blocks tutorial for beginners?
It is lesson 73 of 102 in the free Ruby roadmap, in stage 18, Metaprogramming. If you are new to Ruby, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.