Skip to content

Instantly share code, notes, and snippets.

@prodis
Created July 18, 2011 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prodis/1088491 to your computer and use it in GitHub Desktop.
Save prodis/1088491 to your computer and use it in GitHub Desktop.
Ruby Fundamental - Blocos em Ruby (parte II)
x = 10
5.times do |x|
puts "x inside the block: #{x}"
end
puts "x outside the block: #{x}"
x inside the block: 0
x inside the block: 1
x inside the block: 2
x inside the block: 3
x inside the block: 4
x outside the block: 10
x = 10
5.times do |y|
x = y
puts "x inside the block: #{x}"
end
puts "x outside the block: #{x}"
x inside the block: 0
x inside the block: 1
x inside the block: 2
x inside the block: 3
x inside the block: 4
x outside the block: 4
x = 1200
puts "Before the loop, x = #{x}"
3.times do|y; x|
puts "Looping #{y}"
x = y
end
puts "After the loop, x = #{x}"
Before the loop, x = 1200
Looping 0
Looping 1
Looping 2
After the loop, x = 1200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment