Lambda creation and behavior
📖 Scenario: You are working on a small Ruby program that uses lambdas to perform simple math operations. Lambdas are like little machines that take input and give output. You will create a lambda, set up a value to use with it, run the lambda, and then show the result.
🎯 Goal: Build a Ruby program that creates a lambda to double a number, applies it to a given number, and prints the result.
📋 What You'll Learn
Create a lambda called
double that takes one argument and returns it multiplied by 2Create a variable called
number and set it to 7Call the
double lambda with number as input and store the result in doubled_numberPrint the value of
doubled_number💡 Why This Matters
🌍 Real World
Lambdas are useful for small tasks you want to reuse, like math operations or filtering lists.
💼 Career
Understanding lambdas helps you write cleaner, more flexible Ruby code, which is valuable in many programming jobs.
Progress0 / 4 steps