Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stacietaylorcima/4cc79a4af40f7b3215bee78c8cc8c4ba to your computer and use it in GitHub Desktop.
Save stacietaylorcima/4cc79a4af40f7b3215bee78c8cc8c4ba to your computer and use it in GitHub Desktop.
This checkpoint instructs the student to "in just a few sentences, the message should describe a toaster (the kitchen appliance) in the terminology of a programming method" & "look at a specific block of code and tell your mentor what you think will be printed both from the method body and at the end of the program."

Per the body of this Bloc checkpoint, here are the two requested message assignments.

Note: this does not include the actual assignments listed under the Assignement tab. I will include those details in my final Submission.


Toaster Function

If I were to write a method that executes the functionality of an actual toaster, it might read something like this:

  • The keyword def tells Ruby that I am about to define a method.
  • toaster is the name assigned to the method.
  • food inside of a parenthesis is the parameter. Arguments passed through when the method is actually called must be edible items.
  • Inside the block of code, I might include a conditional that tells the program if the argument passed through is not an edible item, return ‘Stop, that item cannot be toasted!’ else run code that will actually toast the item and return, ‘be careful, it’s hot!’
  • The key work end tells Ruby to close the function

Method Example: peer_pressure

My initial thoughts before running the code in the peer_pressure example were this:

Define Variable & Method:

  • First, we are defining a variable, favorite_social_network, and setting it to refer to the value “Myspace”
  • Then, we are defining a method, peer_pressure. Within the peer_pressure method, we are re-assigning the variable favorite_social_network to refer to the value “Facebook” and then instructing the program to print that value.

The Results:

  • Now, if you call the method peer_pressure (line 8) you should get: “Facebook”
  • If you print the true value of favorite_social_network (line 9) you should get: “Facebook”
    • This is because we reset the value of favorite_social_network to “Facebook” in the peer_pressure method so anytime we inspect the value of that variable, we will get the most recently assigned value because variables “can be reassigned at any time and will only keep the latest assigned value.” (Bloc Checkpoint 1: Intro to Ruby)

Inaccurate Thought Process:

  • I ran the code to validate my thinking and found that no matter where in the code I run the line p favorite_social_network I get “Myspace”.

Requested Assistance:

  • I am not understanding why assigning the value of the variable favorite_social_network to “Facebook” in the peer_pressure method is not updating the true value of the variable favorite_social_network when inspected after the method has been called.
  • I have done some research and can’t find an answer. Perhaps you can help me figure out what specific terms I should be Googling OR we can discuss in our upcoming mentor meeting.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment