Skip to content

Commit

Permalink
Update methods lesson.
Browse files Browse the repository at this point in the history
  • Loading branch information
KatBrandt committed Nov 15, 2023
1 parent bb95847 commit 4d4b1bd
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions module1/lessons/methods_and_return_values.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tags: ruby, methods, return, argument

## Warmup

With your breakout group, define the following terms in your own words:
Define the following terms in your own words:

* Variable
* Method
Expand All @@ -35,6 +35,10 @@ With your breakout group, define the following terms in your own words:

Then, for each of the terms above, identify examples in the pry snippets below (these snippets will also work in irb):

* To install pry, type `gem install pry` in your terminal.
* To use pry, type `pry` into your terminal to open up a _pry session_.
* You can then use this to type Ruby code.

```ruby
pry(main)> "Hello World".upcase
=> "HELLO WORLD"
Expand Down Expand Up @@ -72,16 +76,10 @@ You are calling the `upcase` method. It's job is to create a version of the Stri
<br>
<br>

**Breakout Chat**: Imagine the `upcase` method didn't exist. How might you recreate this method in Ruby?

<br>
<br>
<br>
<br>

One of the most important reasons we need methods is to **reuse code**. Instead of rewriting all those lines of code for creating an upcased string, we simply call the `upcase` method.

The example illustrates another key point: **methods run on objects**. In the example above, the `upcase` method is running on `"Hello World"`, which is a String object. You can think of methods like they are messages to an object. The above code is like saying, "Hey string, give me an upcased version of yourself."
The example illustrates another key point: **methods run on objects**. In the example above, the `upcase` method is running on `"Hello World"`, which is a **String object**. You can think of methods like they are messages to an object. The above code is saying, "Hey string, give me an upcased version of yourself."

To recap the Key Points from this section:
- We use methods so we can reuse code
Expand Down

0 comments on commit 4d4b1bd

Please sign in to comment.