• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/3

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

3 Cards in this Set

  • Front
  • Back
Side Effects
There are also methods that return nothing; we just use for their side-effects. When we say side-effect, we mean some sort of modification to a non-local variable or some sort of observable interaction with calling methods or the outside world.

A great example of a method that is used for its side effect is puts. Another one is each. each returns the original array (which provides no new information and is therefore not terribly useful) and thus is used exclusively for its side-effects.
Explicit vs. Implicit returns
Ruby has implicit returns, that is, the last evaluated expression in a method is the return value of that method. Because of implicit returns, we only use explicit returns when we want an early return, such as in the following method:

def go_home
return unless can_go_home? && wants_to_go_home?

pack_bags
get_tickets
board_plane
end
Good Methods
1. Your methods should be as simple as possible. In particular, they should do one thing;

2. You should be explain what it does in a single sentence. You should be able to give it a straightforward, descriptive name.

3. They should be <10 lines of code