×

ruby · level 1 · unit 7 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

A method is a recipe card with a name on top.

You have used methods like upcase. Now you can make your own: a set of instructions wrapped up under one name. Write the recipe once, then cook it as often as you like, without copying a single line.

Start with , short for define, then the name. The lines underneath are the recipe, and end closes the card. Writing the card does not run it.

To the method, write its name on a line of its own, like cheer. Every line in the recipe then runs, top to bottom. Call it twice and it runs twice.

def cheer
  puts "Go team!"
  puts "You can do it!"
end
cheer
cheer

Change the recipe and every call uses the new version.