Click here to navigate the course.

Drag the edges to resize the window.

In Projects, you can keep track of your progress as you go throught the tasks. Check each item as you complete it!

Code Editor
Learn
Methods, Blocks, & Sorting

Why Methods?

A method is a reusable section of code written to perform a specific task in a program. You might be wondering why you need to separate your code into methods, rather than just writing everything out in one big chunk. It turns out there are a few good reasons to divide your programs into methods:

  1. If something goes wrong in your code, it's much easier to find and fix bugs if you've organized your program well. Assigning specific tasks to separate methods helps with this organization.

  2. By assigning specific tasks to separate methods (an idea computer scientists call separation of concerns), you make your program less redundant and your code more reusable—not only can you repeatedly use the same method in a single program without rewriting it each time, but you can even use that method in another program.

  3. When we learn more about objects, you'll find out there are a lot of interesting things we can do with methods in Ruby.

Instructions

Check out the method we've written in the editor. Can you guess what it will do? Click Run when you think you know!

Report a Bug
If you see a bug or any other issue with this page, please report it here.