Locked lesson.
About this lesson
Understanding methods in Ruby.
Exercise files
Download this lesson’s related exercise files.
Methods.docx60.4 KB Methods - Solution.docx
59.7 KB
Quick reference
Methods
Methods are like programs inside of your programs that only get executed when you call them.
When to use
Use methods whenever you can!
Instructions
To create a method:
def method_name
# your code here
end
To call a method:
method_name
To create a method that accepts parameters from outside itself:
def method_name(parameter)
# your code here
end
And to pass in a paramter when calling the method:
method_name(parameter)
Hints & tips
- Methods are programs inside your program
- Methods only get executed if you call them
- To call a methods, just type its name
Lesson notes are only available for subscribers.