Sometimes we don’t just want a method to print something to the console, but we actually want that method to hand us (or another method!) back a value. For that, we use
def double(n) return n * 2 end output = double(6) output += 2 puts output
doublethat accepts one argument called
doublemethod with an argument of
6and store the result,
outputto 14 and print it out to the console.
Define a new method called
add that takes two numbers as arguments.
Inside the method,
return the sum of those numbers.