Skip to content

Instantly share code, notes, and snippets.

@megstang
Created August 19, 2020 04:02
Show Gist options
  • Save megstang/b2a97b1151facb99ac01e6811f49cb25 to your computer and use it in GitHub Desktop.
Save megstang/b2a97b1151facb99ac01e6811f49cb25 to your computer and use it in GitHub Desktop.
Block Scope Examples 14-19

Example 14

numbers = [1,2,3]
total = 0
numbers.each do |number|
  total += number
end

p total

Example 15

numbers = [1,2,3]
total = 0
numbers.each do |number|
  pizza = "yummy!"
  total += number
end

p pizza

Example 15

numbers = [1,2,3]
total = 0
numbers.each do |number|
  total += number
end

p number

Example 17

numbers = [1,2,3]
number = 0
numbers.each do |number|
  puts number
end

Example 18

numbers = [1,2,3]
numbers.each do |number|
  number = 0
  puts number
end

Example 19

numbers = [1,2,3]
def number
  0
end
numbers.each do |number|
  puts number
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment