Suggested response format (based on feedback from other students & Srdjan’s blog post):

Using Markdown: use backticks (Markdown formatting) to highlight variable names, methods, and lines you are referring to: On line 1 we initialize the local variable…

Always aim to answer: What does the following code output and return? Why? What concept does it demonstrate?

`

Additional Practice Problems:

  1. Collection Methods from Lesson 4
  2. Ruby Basics: Variable Scope
  3. Ruby Basics: Return

Local Variable Scope

Example 1

What does the following code return? What does it output? Why? What concept does it demonstrate?

a = “Hello”
b = a
a = “Goodbye”

puts a
puts b

Example 2

What does the following code return? What does it output? Why? What concept does it demonstrate?

a = 4

loop do  
  a = 5  
  b = 3

  break
end

puts a
puts b

Example 3