Why methods always return a value in Ruby
📖 Scenario: Imagine you are baking cookies and you want to know how many cookies you made after baking. In Ruby, methods are like your baking process. They always give you a result back, just like you always get cookies after baking.
🎯 Goal: You will create a simple Ruby method that adds two numbers and see how it always returns a value, even if you don't explicitly say so.
📋 What You'll Learn
Create a method called
add_numbers that takes two parameters a and bInside the method, add
a and b without using the return keywordCreate a variable called
result that calls add_numbers with 5 and 7Print the value of
result💡 Why This Matters
🌍 Real World
Understanding that methods always return a value helps you write clear and predictable Ruby programs, like calculating totals or processing data.
💼 Career
Ruby developers often rely on implicit returns to write concise code, which is common in web development and scripting tasks.
Progress0 / 4 steps