Skip to content

Instantly share code, notes, and snippets.

@cjsim89
Forked from megstang/block_scope_examples.md
Created December 1, 2021 23:17
Show Gist options
  • Save cjsim89/cf69280c59814af24707e741e17a6f96 to your computer and use it in GitHub Desktop.
Save cjsim89/cf69280c59814af24707e741e17a6f96 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 16

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