Methods, Blocks & Sorting Flashcards
1
Q
Method
A
A method is a reusable section of code written to perform a specific task in a program.
2
Q
3 Reasons to Separate Code into Methods
A
- Better organization / Easier to Find & Fix bugs
- Makes code less redundant and more reusable
- Easier to work with objects
3
Q
Separation of Concerns
A
Assigning specific tasks to individual methods
4
Q
3 Parts of a Method
A
- Header - includes the def keyword (or { ), the method name, and any arguments the method takes
- Body - ode block that describes the procedures the method carries out
- End - all methods finish with the end keyword (or } )
5
Q
How to you call a method?
A
Just type its name in the code.
6
Q
Splat Argument
A
Splat arguments are parameters that are preceded by a *
They allow for a wildcard number of inputs of the individual parameter