Methods

Learn about methods and how to use them in Ruby.

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. ...