- Understand what a function / method is
- Learn how to define a method with and without a return value
- A function is a block of organized, reusable code that is used to perform a single, related action
- they can have inputs (aka arguments) and outputs
f(x) = 2x + 5
Note:
Go over what would be considered the input + output
def f(x) # def, name of method, arguments for method
return 2*x + 5
endNote:
Tell them in Ruby, methods + functions are interchangeable terms
- The value that follows the
returnis the output of a function - Not all functions need to return something, but typically do
Note:
go over what the return statement does and implicit returns
-
Define a method that takes two integer values as arguments and returns the sum of the values.
-
Define a method that takes an array of integer values and returns the sum of those integer values.
- What a method is
- Anatomy of a method
returnstatement