Proc composition
📖 Scenario: You are working on a small Ruby program that processes numbers using reusable pieces of code called Procs. Procs are like little machines that take input and give output. You want to combine these machines to create a new machine that does two things in order.
🎯 Goal: Build a Ruby program that creates two simple Procs, then combines them into one Proc that applies both steps in sequence. Finally, run the combined Proc on a number and see the result.
📋 What You'll Learn
Create two Procs named
double and increment.double should multiply its input by 2.increment should add 1 to its input.Create a new Proc called
double_then_increment that applies double first, then increment.Call
double_then_increment with the number 3 and print the result.💡 Why This Matters
🌍 Real World
Proc composition is useful when you want to build complex operations from simple reusable steps, like processing data or applying filters.
💼 Career
Understanding Proc composition helps in writing clean, modular Ruby code often used in web development and scripting tasks.
Progress0 / 4 steps