Pure Functions Concept
📖 Scenario: Imagine you are building a simple calculator that adds numbers without changing anything outside the calculator. This means the calculator should always give the same answer for the same numbers and never change any other data.
🎯 Goal: You will create a pure function in Ruby that adds two numbers and returns the result without changing any outside data.
📋 What You'll Learn
Create a method called
add_numbers that takes two parameters: a and b.Inside the method, return the sum of
a and b.Create two variables called
num1 and num2 with values 5 and 7 respectively.Call the
add_numbers method with num1 and num2 as arguments and store the result in a variable called result.Print the value of
result.💡 Why This Matters
🌍 Real World
Pure functions are used in many programs to make sure calculations are reliable and do not cause unexpected changes.
💼 Career
Understanding pure functions is important for writing clean, testable, and maintainable code in software development jobs.
Progress0 / 4 steps