Created
November 11, 2008 03:41
-
-
Save DylanFM/23733 to your computer and use it in GitHub Desktop.
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
i, @i = 1, 1 | |
def add_one(i) | |
i =+1 | |
end | |
add_one(i) | |
add_one(i) | |
add_one(i) | |
puts i #=> 1 | |
def add_one(i) | |
@i = i+1 | |
end | |
add_one(@i) | |
add_one(@i) | |
add_one(@i) | |
puts @i #=> 4 | |
i, @i = 1, 1 | |
def add_one(i, &block) | |
i = i+1 | |
yield i | |
end | |
add_one(i) { |i| i = i*5 } | |
puts i #=> 10 | |
add_one(@i) { |i| @i = i*5 } | |
puts @i #=> 10 | |
i, @i = 1, 1 | |
def add_one(i, &block) | |
@i = i+1 | |
yield i | |
end | |
add_one(i) { |i| i = i*5 } | |
puts i #=> 5 | |
add_one(@i) { |i| @i = i*5 } | |
puts @i #=> 10 | |
i, @i = 1, 1 | |
class Numeric | |
def add_one | |
self + 1 | |
end | |
end | |
1..40.times do | |
i = i.add_one | |
end | |
puts i #=> 41 | |
1..40.times do | |
@i = @i.add_one | |
end | |
puts @i #=> 41 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment