Created
July 18, 2011 03:28
-
-
Save prodis/1088491 to your computer and use it in GitHub Desktop.
Ruby Fundamental - Blocos em Ruby (parte II)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = 10 | |
5.times do |x| | |
puts "x inside the block: #{x}" | |
end | |
puts "x outside the block: #{x}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = 10 | |
5.times do |y| | |
x = y | |
puts "x inside the block: #{x}" | |
end | |
puts "x outside the block: #{x}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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