Usage
Learn how to use methods in Ruby after defining them.
Calling a method
We can only use a method after we’ve defined it. As programmers, we usually say that we call a method. This means we ask Ruby to execute the code that the method body has, with some given arguments (if any).
Here’s how that looks:
Press + to interact
Ruby
def add_two(number)number + 2endputs add_two(3)
Explanation
Let’s inspect what’s happening here in more detail, though it might seem confusing at first
In the first three lines, Ruby defines the add_two
method as discussed before. ...