Methods
Explore how to create and use methods in Ruby to organize code into logical, reusable parts. Understand the role of parameters and return values to write clearer and maintainable programs.
We'll cover the following...
We'll cover the following...
Purpose of methods
Methods, or functions, are small chunks of code that we can reuse. Until now, we haven’t reused the code that we wrote, except for the code inside of blocks. But with methods, we can improve and optimize our programs by splitting them into multiple logical blocks.
Methods shouldn’t necessarily make our programs shorter. The main idea is to define the logical parts and make the program more readable for a human. Sometimes, this process is called refactoring. There are many refactoring techniques, and this particular technique is called ...